From c30b5812d1628c22789f5673a1f690d22c60d998 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 7 Nov 2008 12:09:39 +0000 Subject: [PATCH] API CHANGE Don't include NULL returns in decorated methods called through Object->extend(), meaning empty method bodies in decorators won't confuse permission checks through $myObj->extend('canView') etc. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65451 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Object.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/Object.php b/core/Object.php index de329be62..955f79b6d 100755 --- a/core/Object.php +++ b/core/Object.php @@ -459,19 +459,24 @@ class Object { * originally returned void, so if you wanted to return results, you're hosed. * * Currently returns an array, with an index resulting every time the function is called. + * Only adds returns if they're not NULL, to avoid bogus results from methods just + * defined on the parent decorator. This is important for permission-checks through + * extend, as they use min() to determine if any of the returns is FALSE. + * As min() doesn't do type checking, an included NULL return would fail the permission checks. * * @param string $funcName The name of the function. * @param mixed $arg An Argument to be passed to each of the extension functions. */ public function extend($funcName, &$arg=null) { if($this->extension_instances) { - $return = array(); + $returnArr = array(); foreach($this->extension_instances as $extension) { if($extension->hasMethod($funcName)) { - $return[] = $extension->$funcName($arg); + $return = $extension->$funcName($arg); + if($return !== NULL) $returnArr[] = $return; } } - return $return; + return $returnArr; } }