diff --git a/library/Zend/View/Renderer/PhpRenderer.php b/library/Zend/View/Renderer/PhpRenderer.php index 87baf3d988f..f2242a5f5c1 100644 --- a/library/Zend/View/Renderer/PhpRenderer.php +++ b/library/Zend/View/Renderer/PhpRenderer.php @@ -396,7 +396,7 @@ public function __call($method, $argv) $this->__pluginCache[$method] = $this->plugin($method); } if (is_callable($this->__pluginCache[$method])) { - return call_user_func_array($this->__pluginCache[$method], $argv); + return call_user_func_array($this->plugin($method), $argv); } return $this->__pluginCache[$method]; } diff --git a/tests/ZendTest/View/PhpRendererTest.php b/tests/ZendTest/View/PhpRendererTest.php index 12c6aff1578..01aa11acdad 100644 --- a/tests/ZendTest/View/PhpRendererTest.php +++ b/tests/ZendTest/View/PhpRendererTest.php @@ -421,4 +421,25 @@ public function testIfViewModelComposesVariablesInstanceThenRendererUsesIt() $test = $this->renderer->render($model); $this->assertContains('BAR-BAZ-BAT', $test); } + + /** + * @group ZF2-4221 + */ + public function testSharedInstanceHelper() + { + $helpers = $this->renderer->getHelperPluginManager(); + $helpers->setInvokableClass('sharedinstance', 'ZendTest\View\TestAsset\SharedInstance'); + + $helpers->setShared('sharedinstance',false); + // new instance always created when shared = false + $this->assertEquals(1, $this->renderer->sharedinstance()); + $this->assertEquals(1, $this->renderer->sharedinstance()); + $this->assertEquals(1, $this->renderer->sharedinstance()); + + $helpers->setShared('sharedinstance',true); + // use shared instance when shared = true + $this->assertEquals(1, $this->renderer->sharedinstance()); + $this->assertEquals(2, $this->renderer->sharedinstance()); + $this->assertEquals(3, $this->renderer->sharedinstance()); + } } diff --git a/tests/ZendTest/View/TestAsset/SharedInstance.php b/tests/ZendTest/View/TestAsset/SharedInstance.php new file mode 100644 index 00000000000..a8f97118dba --- /dev/null +++ b/tests/ZendTest/View/TestAsset/SharedInstance.php @@ -0,0 +1,28 @@ +count++; + return $this->count; + } +}