I found the following php bug while using Zend Framework:
If you recursively set a non-existing property to an object (which should call __set() magic method), instead of throwing an error, PHP simply no longer call __set() magic method and simply create a real property on your instance!
Example:
class Fruits{
protected $_props = array(); // inner array mapping properties to values
public function __set($name, $value) {
$this->_props[$name] = $value;
if ('apple' == $name) {
$this->apple = 'green';
}
}
}
$a = new Fruits();
$a->banana = 'yellow';
var_dump(property_exists($a, 'banana')); // output: 'false' as expected
$a->apple = 'red';
var_dump(property_exists($a, 'apple')); // output: 'true'!
As highlighted in above example, instead of throwing a recursivity error, PHP has created ‘apple’ property on the instance. If you try then to update $a->apple, magic method __set() is no longer called since the property do exist! (which is very very annoying).
Here is the link to corresponding php bug ticket: http://bugs.php.net/47215
**************************************
* UPDATE *
**************************************
After all I think it may not be a bug but expected behaviour, otherwise we could not be able to define object properties from within __set() method.