Created
February 4, 2013 18:24
-
-
Save tomasfejfar/4708522 to your computer and use it in GitHub Desktop.
Nasty bug/fail in Zend_View_Abstract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Clear all assigned variables | |
* | |
* Clears all variables assigned to Zend_View either via {@link assign()} or | |
* property overloading ({@link __set()}). | |
* | |
* @return void | |
*/ | |
public function clearVars() | |
{ | |
$vars = get_object_vars($this); | |
foreach ($vars as $key => $value) { | |
if ('_' != substr($key, 0, 1)) { | |
unset($this->$key); | |
} | |
} | |
} |
This was a necessary hack in ZF1. Since the coding standards used underscores to indicate non-public visibility, the way to play nice when extending it is to keep non-public members underscore-prefixed.
There's really no clean way to fix this, as the variables are members of the view object itself. We fixed it in ZF2... but only by making architectural changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One would expect the view variables to be in an array, accessible using magic __set and __get methods. Nope! They are public members of the object! Well, no problem with that!
Until you break ZF convention and use protected variable without underscore or use external library not adhering to those conventions. The above method of Zend_View (used for example in partial() call) will silently unset anything without underscore, despite the fact, that it should only wipe view variables!