Compare references

From: Date: Thu, 15 Aug 2002 20:21:20 +0000
Subject: Compare references
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-8450@lists.php.net to get a copy of this message
I am working on the Config class and I have been able to make it use trees in order to save comments and sections (blocks). In this class, I use a lot of references. In each node, I make references to children and parent. I am now facing a problem I never had with PHP and I don't know how to solve it. Maybe someone here will know... In a child item object, I would like to know which index is the item in its parent children array. I have thought of a method getItemIndex that will walk the parent children array and return the index when both items are the same reference. But I haven't found a function to do that. I know that in other languages like PERL, this can be done with 'eq', but how is it done in PHP ? The code I use is here below but doesn't seem to work all the time. Any hints welcome. TIA Bertrand Mansion Mamasam /** * Returns the item position in its parent children array. * @return int returns int or null if root object */ function getItemIndex() { if (is_object($this->parent)) { $this->flag = true; for ($i = 0; $i < count($this->parent->children); $i++) { if ($this->parent->children[$i]->flag) { $this->flag = false; return $i; } } } return; } // end func getItemIndex

« previous php.pear.dev (#8450) next »