#37731 [Opn->Bgs]: internal reference becomes external
ID: 37731
Updated by: tony2001@php.net
Reported By: nhorton at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Variables related
Operating System: xp
PHP Version: 4.4.2
New Comment:
$this->alpha=&$this->beta;
This line makes $this->aplha to point to $this->beta, i.e. they become
the same variable, so changing alpha changes beta as well and vice
versa.
Previous Comments:
------------------------------------------------------------------------
[2006-06-07 15:55:48] nhorton at gmail dot com
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 )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37731&edit=1
Thread (2 messages)