PHP 4.0 Bug #8661 Updated: a copy of the internal array elements is sometimes not made
| From: | sniper@php.net | Date: | Sun, 14 Jan 2001 22:32:21 +0000 |
| Subject: | PHP 4.0 Bug #8661 Updated: a copy of the internal array elements is sometimes not made | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-44084@lists.php.net to get a copy of this message | ||
ID: 8661
Updated by: sniper
Reported By: lgordon@idiotbrain.com
Status: Open
Old-Bug Type: Class/Object related
Bug Type: Scripting Engine problem
Assigned To:
Comments:
Previous Comments:
---------------------------------------------------------------------------
[2001-01-11 16:46:44] lgordon@idiotbrain.com
Yes, this is the same, if I change the method to
do_nothing() in the Element class and print out a message,
the same behavior happens. The behavior is that if I call a method on an array object after the
array has been copied, the copy now refers to the original. Also, if the method is called on the
original object, the copy is then linked with the original.
---------------------------------------------------------------------------
[2001-01-11 16:41:44] lgordon@idiotbrain.com
This might be the same as 8130, but I'm not sure.
---------------------------------------------------------------------------
[2001-01-11 16:27:34] lgordon@idiotbrain.com
<?php
// buggy.php
// If I leave both A1 and A2 commented out, the code works fine.
// If I uncomment A1 only, the code works as expected
// If I uncomment A2 only, the code does not work as expected
class Element
{
var $val;
function set_value($newval)
{
$this->val = $newval;
}
}
class Owner
{
var $elementArray;
function dump()
{
foreach ($this->elementArray as $index => $value)
{
print("index [$index] value [$value->val]<BR>");
}
}
}
$myOwner = new Owner();
$myOwner->elementArray[0] = new Element;
// -- A1 --
// this works as expected
$myOwner->elementArray[0]->val = 10;
// -- A2 --
// if this line is uncommented the code does not work as expected
//$myOwner->elementArray[0]->set_value(10);
print("dump myOwner<BR>");
$myOwner->dump();
print("<BR>");
print("make a copy of myOwner<BR>");
$copyOwner = $myOwner;
print("<BR>");
print("dump copyOwner<BR>");
$copyOwner->dump();
print("<BR>");
print("change copyOwner index 0 to 999999<BR>");
$copyOwner->elementArray[0]->val = 999999;
print("dump copyOwner<BR>");
$copyOwner->dump();
print("<BR>");
print("dump myOwner<BR>");
$myOwner->dump();
print("<BR>");
?>
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8661