ZF-11683: Zend_View ignore callable properties

Issue Type: Bug Created: 2011-08-18T09:24:27.000+0000 Last Updated: 2012-03-06T14:33:30.000+0000 Status: Resolved Fix version(s): Reporter: Dmitry Kozlovich (dnk1981) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View

  • zf-crteam-review

Related issues: Attachments:


I have a class, for example:

<pre class="highlight">class App_SomeClass
    public method someMethod()
        // ...
    public method __invoke()
        // ...

Pass the link to view: $this->view->someObject = new App_SomeClass(); Now we can call someMethod(): $this->someObject->someMethod(); {color:red}But we can not do so: $this->someObject(); Because Zend begins to look the same name Helpers, Plugins, and so on, ignoring the property.{color} I propose a solution:

<pre class="highlight">abstract class Zend_View_Abstract implements Zend_View_Interface
    // ...

    public function __call($name, $args)
        // is callable property
        if (property_exists($this, $name)) {
            if (is_callable($this->$name)) {
                return call_user_func_array($this->$name, $args);

        // is the helper already loaded?
        $helper = $this->getHelper($name);

        // call the helper method
        return call_user_func_array(
            array($helper, $name),

    // ...

Thank you.


Posted by Matthew Weier O'Phinney (matthew) on 2011-08-18T13:23:19.000+0000

Actually, there's another issue at stake here: you cannot assign callables to properties and invoke them. For example, try the following:

<pre class="highlight">
class A
    public function __invoke()
        echo __CLASS__;

$o = new stdClass;
$o->a = new A;

You'll get a fatal error (call to undefined method).

So, the root cause is actually not how __call() operates, but how PHP operates.

Now, we could potentially add the functionality you indicate here. However, it smells like a BC break -- __call() has only ever proxied to helpers in the past, which has allowed having helpers and properties of the same name. If developers have properties that are callable currently, this would potentially break their systems, as instead of getting the exception, they may now get unexpected results.

In the meantime, while we decide this issue, for your usage, may I suggest using $this->someObject->__invoke()?

Posted by Adam Lundrigan (adamlundrigan) on 2012-03-06T01:51:41.000+0000

I agree that this request would be difficult to implement without causing some level of BC break. Should it be closed as "Wont' Fix" for ZF1, or is it still being considered for 1.12?

Posted by Matthew Weier O'Phinney (matthew) on 2012-03-06T14:33:22.000+0000

On thinking about this, I don't think we should do this in ZF1. I have some functionality in ZF2 to somewhat mimic this behavior, but it's definitely BC-breaking behavior against ZF1.

In ZF1, I'd do:

<pre class="highlight">
$helper = $this->someObject;

This will work regardless of PHP version, as well as regardless of ZF version.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.