note 16194 added to language.references.arent
| From: | jthurtea at unity dot ncsu dot edu | Date: | Fri, 19 Oct 2001 15:19:13 +0000 |
| Subject: | note 16194 added to language.references.arent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19158@lists.php.net to get a copy of this message | ||
A warning about bi-directional referencing.
After several hours of tearing my hair out I think I finally figured out why scripts containing
objects with bi-directional references (double linked-lists, trees) are looping infinately.
It would appear that when testing for equality ( == or === ) in objects that PHP4 does not simply
compare objects and references in a shallow manner. In addition to making sure they point to the
same object it will test to see that all properties of that object are equal, and if any of those
properties are also an object it will assert that all of it's properties are equal. . . and so
if you have an object that points to something and that object either directly, or indirectly points
back to the first object the program will enter into an infinate loop.
For eaxmple:
class ll{
var myNext;
function ll(){
}
}
would have no problems, but:
class dll{
var myNext;
var myPrev;
function dll(){
}
}
will have problems. There is some documentation on how to work around the problem, but it is hard to
find. You can implement the structure using a central array of references ( an array inside the
"root" object in the structure or outside the structure ). An example of this is in
Chapter 2 of Web Applications Development with PHP 4.0 by Tobias Ratschiller and Till Gerken. You
can place new objects into the array and then reference them ( and compare them ) by their index in
the array.
--
http://www.php.net/manual/en/language.references.arent.php
http://master.php.net/manage/user-notes.php?action=edit+16194
http://master.php.net/manage/user-notes.php?action=delete+16194
http://master.php.net/manage/user-notes.php?action=reject+16194