diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php index e8faa8096..769dd7049 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGet.php @@ -41,7 +41,7 @@ class MagicGet extends MagicMethodGenerator * @var string */ private $callParentTemplate = <<<'PHP' -%s +$this->%s && ! $this->%s && $this->%s('__get', array('name' => $name)); if (isset(self::$%s[$name])) { return $this->$name; @@ -137,8 +137,9 @@ public function __construct( $this->setBody(sprintf( $this->callParentTemplate, - '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() - . '(\'__get\', array(\'name\' => $name));', + $initializerProperty->getName(), + $initializationTracker->getName(), + $callInitializer->getName(), $publicProperties->getName(), $protectedProperties->getName(), $initializationTracker->getName(), diff --git a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php index 96582cf0a..e9b2395de 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/MagicGetTest.php @@ -74,7 +74,7 @@ class MagicGetTest extends PHPUnit_Framework_TestCase * @var string */ private $expectedCode = <<<'PHP' -$this->foo && $this->baz('__get', array('name' => $name)); +$this->foo && ! $this->init && $this->baz('__get', array('name' => $name)); if (isset(self::$bar[$name])) { return $this->$name;