PHP Indirect modification of overloaded property

sdabme

New Member
i have this simple class:\[code\]class A{ var $children=array(); function &__get($name) { if($name==="firstChild") { if(count($this->children)) $ret=&$this->children[0]; else $ret=null; } return $ret; }}\[/code\]By accessing the "firstChild" property it should return its first child by reference or null if there are no children.\[code\]$a=new A;$c=&$a->firstChild;\[/code\]Now if the class contains at least one child it works great but if it doesn't (and it should return null) it triggers the error "Indirect modification of overloaded property".Why does this happen? I'm not trying to modify anything so what is that "Indirect modification"? And why if i remove the reference sign (\[code\]$c=$a->firstChild;\[/code\]) it works?
 
Back
Top