|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-06-20 14:15 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 05:00:01 2025 UTC |
Description: ------------ this sure seems like a bug to me. referencing alpha to beta causes a reference to be set up between all further iterations of the object. delta, without the reference, behaves normally. i also tried it using foreach loops instead of for loops, same thing happened. Reproduce code: --------------- class one{ function one($i){ $this->beta=$i; $this->alpha=&$this->beta; $this->delta='diamond'; } } for($i=0;$i<11;$i++){ $one= new one($i); $array[]=$one; } for($i=0;$i<11;$i++){ $first_object=$array[$i]; $second_object=$first_object; } echo "<br>before loop<br>"; print_r($second_object); for($i=0;$i<11;$i++){ $object=$array[$i]; $object->alpha='xxxx'; $object->delta='spade'; } echo "<br>after loop<br>"; print_r($second_object); Expected result: ---------------- expected output: before loop one Object ( [beta] => 10 [alpha] => 10 [delta] => diamond ) after loop one Object ( [beta] => 10 [alpha] => 10 [delta] => diamond ) Actual result: -------------- output: before loop one Object ( [beta] => 10 [alpha] => 10 [delta] => diamond ) after loop one Object ( [beta] => xxxx [alpha] => xxxx [delta] => diamond )