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 669103cbdaf..edbcaa2ba89 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 testSharedInstanceHelperTest() + { + $helpers = $this->renderer->getHelperPluginManager(); + $helpers->setInvokableClass('sharedinstancetest', 'ZendTest\View\TestAsset\SharedInstanceTest'); + + $helpers->setShared('sharedinstancetest',false); + // new instance always created when shared = false + $this->assertEquals(1, $this->renderer->sharedinstancetest()); + $this->assertEquals(1, $this->renderer->sharedinstancetest()); + $this->assertEquals(1, $this->renderer->sharedinstancetest()); + + $helpers->setShared('sharedinstancetest',true); + // use shared instance when shared = true + $this->assertEquals(1, $this->renderer->sharedinstancetest()); + $this->assertEquals(2, $this->renderer->sharedinstancetest()); + $this->assertEquals(3, $this->renderer->sharedinstancetest()); + } }