ZF-2934: CLONE -Zend_View_Interface sample causes Warning
Description
In Zend_View_Smarty, when using an array append operation (eg. $view->myArray[] = 'foo';) the __get overload function produces this notice: Notice: Indirect modification of overloaded property ...
To fix this you have to pass by reference - but the Zend_View_Interface/Zend_View_Abstract __get method doesn't pass by reference so I fixed it like this:
change:
public function __get($key)
{
return $this->_smarty->get_template_vars($key);
}
to:
public function __get($key)
{
return is_array($this->_smarty->get_template_vars($key)) ? new ArrayObject($this->_smarty->get_template_vars($key)) : $this->_smarty->get_template_vars($key);
}
I'm sure there's some way to make this more pretty by using a temp var or something, but I wanted it to be fast and simple.
Comments
Posted by Alex Peterson (alx) on 2008-03-20T12:17:42.000+0000
OK, this get's rid of the notice but it still doesn't work (it doesn't append to the array still). Any ideas how to make this work right?
Posted by Alex Peterson (alx) on 2008-03-20T14:40:28.000+0000
This should work: First, make sure that Zend_View_Smarty doesn't extend Zend_View_Abstract and then change:
public function __get($key)
to
public function &__get($key)
By passing by reference you no longer have the issues with appending to array's etc. The ArrayObject method i tested above didn't work because Smarty wouldn't iterate over the ArrayObject like an array in my testing.
Posted by Wil Sinclair (wil) on 2008-04-18T12:47:47.000+0000
Fixing obviously incorrect fix for version (fix version < affects version).
Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T13:33:39.000+0000
Scheduling for next minor release.
Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2008-11-30T23:37:54.000+0000
Now, Zend_View_Interface has no __get() function.
So, __get() function should be removed from zend.view.scripts.html#zend.view.scripts.templates.interface .
Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2008-12-01T04:34:37.000+0000
Solved in SVN 12965
Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2008-12-01T21:43:59.000+0000
This fix will be released in ver. 1.7.2