Bug #8130 Updated: Changing a copy of an array affects the original
| From: | wstockal at msysgroup dot com | Date: | Tue, 28 Aug 2001 21:26:13 +0000 |
| Subject: | Bug #8130 Updated: Changing a copy of an array affects the original | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-64545@lists.php.net to get a copy of this message | ||
ID: 8130
User updated by: wstockal@msysgroup.com
Reported By: wstockal@msysgroup.com
Status: Closed
Bug Type: Scripting Engine problem
Operating System: Redhat Linux 6.2
PHP Version: 4.0.6-dev
New Comment:
This problem can also affect the private copies of variables
used inside of functions.
Script:
class test {
var $property;
function do_something(){
return;
}
}
function mangle($array_in) {
$array_in[0]->property = 'trashed';
}
$array[0] = new test;
$array[0]->property = 'ok';
mangle($array);
echo("<h2>Before:</h2>\n");
echo("\$array[0]->property is {$array[0]->property}<br>\n");
$array[0]->do_something();
mangle($array);
echo("<h2>After:</h2>\n");
echo("\$array[0]->property is {$array[0]->property}<br>\n");
Output:
<h2>Before:</h2>
$array[0]->property is ok<br>
<h2>After:</h2>
$array[0]->property is trashed<br>
Previous Comments:
------------------------------------------------------------------------
[2001-06-17 04:54:11] jmoore@php.net
This will not be fixed anytime soon. It is a deep seated problem in the implementation and fixing it
would cause speed problems and numerous other problems, This is somthing that can be coded around
too so should not cause massive problems.
- James
------------------------------------------------------------------------
[2001-04-28 15:27:42] jmoore@php.net
Reproduced in 4.0.6-dev one for the bug squash
------------------------------------------------------------------------
[2001-01-06 02:38:08] cynic@php.net
Confirmed in 4.0.4pl1 RC1
------------------------------------------------------------------------
[2000-12-07 02:28:51] wstockal@msysgroup.com
Is this the same as bug 6417?
------------------------------------------------------------------------
[2000-12-06 11:23:23] wstockal@msysgroup.com
OK, this only affects objects in the array whose methods
have been accessed. Other objects are still copies. It
also works on php-4.0.3pl1 on the Win32 platform.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/?id=8130
Edit this bug report at http://bugs.php.net/?id=8130&edit=1