|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1999-10-09 15:30 UTC] andi at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 08:00:01 2025 UTC |
The object hierachy produced by the following code is corrupted for some reason that I have not been able to determine. If the class variable 'properties' is manipulated directly ther is no problem, however if the helper function 'prop()' is used the data structure is corrupted in that the contents of the 'properties' array are changed. I have been able to determine roughly when this problem arose (through checking out cvs for various days.). It seems to have popped up around the 30th of october. <?php class part{ function part($args=""){ $this->properties=array(); reset($args); while($cur=each($args)){ $this->prop($cur['key'],$cur['value']); } } function prop($var,$arg){ if (!isset($arg)){ // single argument, return current value return $this->properties[$var]; } // set and return new value return $this->properties[$var]=$arg; } function show($indent=""){ echo "${indent}Properties of ".$this->prop("name").":\n"; $indent.="\t"; reset($this->properties); while($cur=each($this->properties)){ //ignore index 'obj' if ($cur['key']!="obj")echo "${indent}${cur['key']} = ${cur['value']} \n"; } } } class assembly extends part{ function assembly($args="",$parts=""){ // call base constructor $this->part($args); $this->properties['obj']=array(); // add parts $this->add($parts); } function add(&$parts){ reset($parts); while($cur=each($parts)){ if (is_object($cur['value'])){ // // uncomment only one of the following '$name=...' lines. // // this method of setting $name works // $name=$cur['value']->properties["name"]; // // this method of setting $name kills the contents of $this->properties... $name=$cur['value']->prop("name"); // $this->properties['obj'][$name]=$cur['value']; } } } function show($indent=""){ // list properties first part::show($indent); if (!is_array($this->properties['obj'])) return; // list member objects echo "${indent}member count is ".sizeof($this->properties['obj'])."\n"; echo "${indent}Members of ".$this->prop("name").":\n"; $indent.="\t"; reset($this->properties['obj']); while($cur=each($this->properties['obj'])){ if (is_object($cur['value'])){ $cur['value']->show($indent); } else{ echo "\nshould be an object, value is '".$cur['value']."'\n"; } } } } $door=new assembly( array( "name"=>"door", "colour"=>"green" ), array( new part( array( "name"=>"panel", "material"=>"wood" ) ), new assembly( array( "name"=>"handle", "type"=>"round" ), array( new part( array( "name"=>"inside knob" ) ), new part( array( "name"=>"outside knob" ) ) ) ) ) ); $door->show(); ?>