note 16194 deleted from language.references.arent by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:23:09 +0000 |
| Subject: | note 16194 deleted from language.references.arent by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57333@lists.php.net to get a copy of this message | ||
Note Submitter: jthurtea@unity.ncsu.edu
----
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.