-- Mathieu Suen <[email protected]> wrote (on Thursday, 16 July 2009, 01:40 PM +0200): > try: > _______ > class A > { > protected $a; > public function __construct() > { > if(!isset($this->a)) > { > $this->a = 'd'; > } > unset($this->a); > if(!isset($this->a)) > { > $this->a = 'd'; > } > } > > public function __set($columnName, $value) > { > echo 'New value : ' . $value . ' for '. $columnName; > } > } > > new A(); > ______ > > This is really not right! '=' have different semantic depending on the > situation. huh! huh!
First off, this question is off-topic for this list. This list is related to usage of Zend Framework; your above question is related more generally to the PHP language itself. As for the question -- the behavior makes perfect sense. In the first conditional, the variable has been declared as an instance variable, but the value is not set; calling $this->a = 'd' then sets the value. It does not need call for overloading as the variable has been declared. You then unset() the variable. This removes the declaration from the class, and thus the second conditional *does* call for overloading. If you want to unset the value but keep the property declared, simply assign it a value of null. -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/
