Zend Framework

CLONE -Zend_View_Interface sample causes Warning

Details

  • Type: Docs:  Improvement Docs: Improvement
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.5.0
  • Fix Version/s: 1.7.2
  • Component/s: Zend_View
  • Labels:
    None
  • Fix Version Priority:
    Nice to Have

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.

Activity

Hide
Alex Peterson added a comment -

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?

Show
Alex Peterson added a comment - 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?
Hide
Alex Peterson added a comment -

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.

Show
Alex Peterson added a comment - 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.
Hide
Wil Sinclair added a comment -

Fixing obviously incorrect fix for version (fix version < affects version).

Show
Wil Sinclair added a comment - Fixing obviously incorrect fix for version (fix version < affects version).
Hide
Matthew Weier O'Phinney added a comment -

Scheduling for next minor release.

Show
Matthew Weier O'Phinney added a comment - Scheduling for next minor release.
Hide
Satoru Yoshida added a comment -

Now, Zend_View_Interface has no __get() function.

So, __get() function should be removed from zend.view.scripts.html#zend.view.scripts.templates.interface .

Show
Satoru Yoshida added a comment - Now, Zend_View_Interface has no __get() function. So, __get() function should be removed from zend.view.scripts.html#zend.view.scripts.templates.interface .
Hide
Satoru Yoshida added a comment -

Solved in SVN 12965

Show
Satoru Yoshida added a comment - Solved in SVN 12965
Hide
Satoru Yoshida added a comment -

This fix will be released in ver. 1.7.2

Show
Satoru Yoshida added a comment - This fix will be released in ver. 1.7.2

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
0m
Remaining Estimate - 0 minutes
Logged:
30m
Time Spent - 30 minutes