Bug #12905: "return" returns a copy of an object instead of a reference

From: Date: Wed, 22 Aug 2001 16:13:08 +0000
Subject: Bug #12905: "return" returns a copy of an object instead of a reference
Groups: php.dev 
Request: Send a blank email to php-dev+get-64054@lists.php.net to get a copy of this message
From: olli@ukgamer.net Operating system: Slackware 7 PHP version: 4.0.6 PHP Bug Type: Scripting Engine problem Bug description: "return" returns a copy of an object instead of a reference <? Class ChildClass { var $value; function ChildClass($value){ $this->value = $value; } } Class ParentClass { var $children; function ParentClass(){ $this->children = array(); } function AddChild($value){ $child = &new ChildClass($value); array_push($this->children, &$child); return $child; } } $p1 = &new ParentClass(); $c1 = &$p1->AddChild('set in constructor'); $c1->value = 'set elsewhere'; echo "the reference to the object created in AddBand and stored in the parentclass' array is different to that returned by the AddBand function<br>"; echo $p1->children[0]->value."<br>"; echo $c1->value; ?> "return" is returning a copy of the object created in parentclass->AddChild instead of a reference. "return &$object" is flagged as invalid by the php interpreter. thanks a lot olli holliday -- Edit bug report at: http://bugs.php.net/?id=12905&edit=1

« previous php.dev (#64054) next »