From 3419d87476d1c570b44099b01b14896793a21ecf Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 12 Jan 2010 23:00:15 +0000 Subject: [PATCH] BUGFIX: Reset the methods applied to classes after adding/removing extensions. (from r89957) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96726 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Object.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/Object.php b/core/Object.php index a0ca325ea..77719988b 100755 --- a/core/Object.php +++ b/core/Object.php @@ -408,6 +408,7 @@ abstract class Object { $subclasses[] = $class; if($subclasses) foreach($subclasses as $subclass) { unset(self::$classes_constructed[$subclass]); + unset(self::$extra_methods[$subclass]); } // merge with existing static vars @@ -476,6 +477,16 @@ abstract class Object { // unset singletons to avoid side-effects global $_SINGLETONS; $_SINGLETONS = array(); + + // unset some caches + self::$cached_statics[$class]['extensions'] = null; + $subclasses = ClassInfo::subclassesFor($class); + $subclasses[] = $class; + if($subclasses) foreach($subclasses as $subclass) { + unset(self::$classes_constructed[$subclass]); + unset(self::$extra_methods[$subclass]); + } + } /** @@ -540,6 +551,12 @@ abstract class Object { * @return mixed */ public function __call($method, $arguments) { + // If the method cache was cleared by an an Object::add_extension() / Object::remove_extension() + // call, then we should rebuild it. + if(empty(self::$cached_statics[get_class($this)])) { + $this->defineMethods(); + } + $method = strtolower($method); if(isset(self::$extra_methods[$this->class][$method])) { @@ -583,6 +600,7 @@ abstract class Object { } } else { // Please do not change the exception code number below. + throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175); } }