__set, __get, etc. have a bug "by design"
PHP Code:
class a
{
private $data = array();
public function __set($key, $val)
{
echo "a sets $key to $val";
$this->data[$key] = $val;
}
}
class b
{
public function foo()
{
echo $this->val;
}
}
$a = new a();
$a->b = new b();
$a->b->c = 'foobar'; // error
That's why my above script puts objects in public and variables in the protected $data.
Same bug happens on arrays
PHP Code:
$a = new a();
$a->b = array('entry');
echo $a->b[0]; // error