ZF-3036: View Filters can have an incorrect View assigned to them

Description

I found what appears to be a bug in the code that performs filtering for views. In the View->getFilter method there is a check for a setView method on the retrieved Filter object. If this method is found the current view will be assigned to the Filter. Since Filters are "cached" in the _filterXXX variables of the View class they can be persistent through multiple runs of the View if a global View has been assigned to the ViewRenderer helper. This is especially true for Layout based sites. This leads to two issues: (a) one View that has Controller Action specified values assigned to it could have those values be available by another View script and (b) Controller assigned View script values not being made available to already instantiated Filters.

The simple fix to this issue is to have the check for the "setView" method pulled out of the current IF block and made in parallel to the primary IF.

Here is the current code (as of 1.5.0):

(Zend_View_Abstract.php)


    public function getFilter($name)
    {
        if (!isset($this->_filterClass[$name])) {
            $class = $this->_loadClass('filter', $name);
            $this->_filterClass[$name] = new $class();
            if (method_exists($this->_filterClass[$name], 'setView')) {
                $this->_filterClass[$name]->setView($this);
            }
        }
        return $this->_filterClass[$name];
    }

Here is my new proposed code:


    public function getFilter($name)
    {
        if (!isset($this->_filterClass[$name])) {
            $class = $this->_loadClass('filter', $name);
            $this->_filterClass[$name] = new $class();
        }
        if (method_exists($this->_filterClass[$name], 'setView')) {
            $this->_filterClass[$name]->setView($this);
        }
        return $this->_filterClass[$name];
    }

Comments

Please evaluate and categorize/assign as necessary.

Updating project management info.

Have you tested this since 1.6 got released where it's using hte plugin manager now instead of the _loadClass Method? If not can you please provide a unitTest for this so we can work on the problem.

Making the code readable.

Closed as Not an Issue as there has been no activity for a while. Please reopen if this is still an issue.