Re: Object-problem

From: Date: Sun, 03 Sep 2000 07:58:00 +0000
Subject: Re: Object-problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14968@lists.php.net to get a copy of this message
Hi, Martin Function params are passed by value (you have a copy of the original object). I think you are comparing two handlers (of two distinct objects). Running your script in my system, working with PHP4, there is a warning: Warning: Cannot compare arrays or objects in .... You can add a class member like an unique id, and compare by this id: if ($s->id == $temp->id) ... Un saludo, Felipe Martin Thoma wrote: > Hello ! > > Another problem of this kind: Could someone tell me, why this is > outputting "No" and what I can do about it ? > > Regards > > Martin > > <?php > > $root = new MenuItem(0); > $temp = new MenuItem($root); > $root->AddChild($temp); > > $s = $root->findFile(""); > > if ($s == $temp) > print "Ok"; > else print "No"; > > class MenuItem > { var $parent; // Parent of the item > var $childs = array(); // All Child-Items > > // Konstruktor > function MenuItem($parent) > { $this->parent = $parent; > } > > // Adds a Child > function AddChild(&$childItem) > { array_push($this->childs, $childItem); > $childItem->parent = $this; > } > > function findFile($fileName) > { return $this->childs[0]; > } > } > > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#14968) next »