Edit report at https://bugs.php.net/bug.php?id=26586&edit=1
ID: 26586
Comment by: will dot skates at ntlworld dot com
Reported by: marc dot daumas at urssaf dot fr
Summary: cross referenced objects
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: WinXP
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Please Close
Previous Comments:
------------------------------------------------------------------------
[2003-12-10 11:45:20] marc dot daumas at urssaf dot fr
Description:
------------
It becomes impossible to compare objects as soon as they have cross references.
if an object A reference an object B that reference A it becomes impossible to
compare objects with == or === operators.
I understood your "reference" system and actualy I know that's not really a bug
but an issue, but at least the === operator must deal with "already seen"
objects.
I just wonder if PHP5 will become a near to real object language or if that
behavior will persist.
Follow a basic example of Parent/Child object structure that can't be
implemented in PHP4.
I think that if it's impossible to work properly with instances, PHP5 will not
ritch the rank of an OOP language despite all that is said about it.
Best regards
-Marc
Reproduce code:
---------------
<?PHP
Class ParentObject {
var $name;
var $chidren;
Function &ParentObject($name){
$this->name=$name;
$this->children=array();
}
Function addChild(&$child){
if(!isset($this->children[$child->name])){
$this->children[$child->name]=&$child;
$child->setParent($this);
}
}
}
Class ChildObject {
var $name;
var $parent;
Function &ChildObject($name){
$this->name=$name;
$this->parent=null;
}
Function setParent(&$parent){
if($this->parent!==$parent){
if($this->parent!=null){
$this->parent->removeChild($this);
}
$this->parent=&$parent;
if($parent!=null){
$parent->addChild($this);
}
}
}
}
$p=&new ParentObject("parent");
$c=&new ChildObject("child");
$c->setParent($p);
?>
Expected result:
----------------
something other than
<b>Fatal error</b>: Nesting level too deep - recursive dependency? in
<b>C:\Program Files\Apache Group\Apache2\htdocs\ngn2\test.php</b> on line
<b>29</b><br />
Actual result:
--------------
<b>Fatal error</b>: Nesting level too deep - recursive dependency? in
<b>C:\Program Files\Apache Group\Apache2\htdocs\ngn2\test.php</b> on line
<b>29</b><br />
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=26586&edit=1