#21288 [Opn]: PHP does referencing when i want to create a *copy* of an array of objects
| From: | moriyoshi@php.net | Date: | Mon, 30 Dec 2002 14:57:32 +0000 |
| Subject: | #21288 [Opn]: PHP does referencing when i want to create a *copy* of an array of objects | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969350500@lists.php.net to get a copy of this message | ||
ID: 21288
Updated by: moriyoshi@php.net
Reported By: empx@gmx.de
Status: Open
Bug Type: Documentation problem
Operating System: Windows XP SP1
PHP Version: 4.3.0
New Comment:
It seems more explanation should have been needed...
This problem is due to misleading behavior of array copies. PHP
scripting engine doesn't perform deep-copy on any elements of an array
while it copies *the container* of them indeed.
This will be fixed in ZendEngine2. Stay tuned.
Previous Comments:
------------------------------------------------------------------------
[2002-12-30 08:45:08] moriyoshi@php.net
Verified. This is yet another "shallow copy" issue.
See http://bugs.php.net/20993
------------------------------------------------------------------------
[2002-12-30 06:52:59] empx@gmx.de
Hello, i have some problems with understanding the following:
class Test {
var $a;
function Test() {
$this->a = 0;
}
function test2() {
}
}
$a[0] = new Test;
$b = $a;
$a[0]->a = 1;
echo($b[0]->a);
This outputs 0 as i would expect..but:
$a[0] = new Test;
$a[0]->test2();
$b = $a;
$a[0]->a = 1;
echo($b[0]->a);
This outputs 1, and i dont understand this, PHP seems to do some sort
of
referencing here, though i dont want any.. $b[0] = $a[0]; works and
creates
a real copy, but i was still wondering if $b = $a shouldnt create a
copy
aswell instead of this referencing stuff...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21288&edit=1