I have been stepping through all the Zend Framework code to see how it all fits 
together, and thinking about how it all will affect the performance of 
applications that are written with it, when I came across something that looks 
odd to me in the the Zend_View_Abstract::_getPlugin() implementation. 
Specifically the function is as follows:

    private function _getPlugin($type, $name)    {        $name = 
ucfirst($name);        switch ($type) {            case 'filter':               
 $storeVar = '_filterClass';                $store    = $this->_filterClass;    
            break;            case 'helper':                $storeVar = 
'_helper';                $store    = $this->_helper;                break;     
   }        if (!isset($store[$name])) {            $class = 
$this->getPluginLoader($type)->load($name);            $store[$name] = new 
$class();            if (method_exists($store[$name], 'setView')) {             
   $store[$name]->setView($this);            }        }        $this->$storeVar 
= $store;        return $store[$name];    }
The thing that has me wondering is the second last line. This line re-assigns 
the $store value into the $this->_helper or $this->_filterClass variables. But 
in the case where the plugin has already been loaded and already exists in 
$store, this is just re-assigning the same value. I don't know how PHP 
optimizes things, but I would expect this would cause the entire array to be 
re-assigned, and the original contents of the array to go onto the garbage 
collection heap. Since the contents have not changes, shouldn't this be written 
this way?

        if (!isset($store[$name])) {            $class = 
$this->getPluginLoader($type)->load($name);            $store[$name] = new 
$class();            if (method_exists($store[$name], 'setView')) {             
   $store[$name]->setView($this);            }            $this->$storeVar = 
$store;        }        return $store[$name];
Regards,

Kendall Bennett, CEO
A Main Hobbies
424 Otterson Drive, Suite 160
Chico, CA 95928
1-800-705-2215 (Toll-Free)
1-530-894-0797 (Int'l & Local)
1-530-894-9049 (Fax)
http://www.amainhobbies.com

Regards,

Kendall Bennett, CEO
A Main Hobbies
424 Otterson Drive, Suite 160
Chico, CA 95928
1-800-705-2215 (Toll-Free)
1-530-894-0797 (Int'l & Local)
1-530-894-9049 (Fax)
http://www.amainhobbies.com

Reply via email to