array in the class

From: Date: Sat, 02 Dec 2000 12:37:03 +0000
Subject: array in the class
Groups: php.general 
Request: Send a blank email to php-general+get-28358@lists.php.net to get a copy of this message
hi, I have defined container class Sample: class Sample { var $name; var $parsed = array(); function Sample ($name) { $this->name = $name; } function set_parsed($parsed) { $this->parsed=$parsed; } function print_me() { for (reset($this->parsed);$tmp=current($this->parsed);next($this->parsed)){ $tmp->print_me(); } print "Name: $this->name <br>\n "; } } Now I try sample usage: $a= new Sample("One"); $b= new Sample("Two"); $c= new Sample("Three"); $a->set_parsed(array($b)); $b->set_parsed(array($c)); $a->print_me(); which print the strange result: Name: Two Name: One but when I switch the set_parsed calls: $a= new Sample("One"); $b= new Sample("Two"); $c= new Sample("Three"); $b->set_parsed(array($c)); $a->set_parsed(array($b)); $a->print_me(); I obtain right (imho) result: Name: Three Name: Two Name: One Where is the problem? I use PHP Version 4.0.1pl2. thanks -- Arnost Stedry Ustav informatiky

« previous php.general (#28358) next »