#21288 [Com]: PHP does referencing when i want to create a *copy* of an array of objects
| From: | phpbg at cytrax dot de | Date: | Tue, 03 Aug 2004 13:11:24 +0000 |
| Subject: | #21288 [Com]: 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-969362529@lists.php.net to get a copy of this message | ||
ID: 21288
Comment by: phpbg at cytrax dot de
Reported By: empx at gmx dot de
Status: Bogus
Bug Type: Documentation problem
Operating System: Windows XP SP1
PHP Version: 4.3.0
New Comment:
Ho can I create a *real* copy of an array or to make having no
references.
foreach does not create a real copy if the array has references on
objects in it.
Is there any function to find out if the array-entry is an object or
only a reference?
Previous Comments:
------------------------------------------------------------------------
[2004-06-30 04:13:50] moriyoshi@php.net
As explained in bug #20993, this is assumed to be expected behaviour
and will unlikely be *fixed* ever.
------------------------------------------------------------------------
[2004-04-18 04:15:24] php dot devel at homelinkcs dot com
> This will be fixed in ZendEngine2. Stay tuned.
Downloaded, compiled and tested PHP 5.0.0RC1 and all tests
yielded same result as 4.3.4. Example:
[josh@joshua php-5.0.0RC1]$ sapi/cli/php
<?php
print phpversion()."\n";
$a[0] = "original"; $b =& $a[0]; $c = $a; $c[0] = "copy";
print $a[0]."\n";
?>
5.0.0RC1
copy
[josh@joshua php-5.0.0RC1]$ php
<?php
print phpversion()."\n";
$a[0] = "original"; $b =& $a[0]; $c = $a; $c[0] = "copy";
print $a[0]."\n";
?>
4.3.4
copy
[josh@joshua php-5.0.0RC1]$
------------------------------------------------------------------------
[2002-12-30 09:39:47] stephan at wanderinghorse dot net
Just FYI, i've reproduced this (using the code from the
original poster) on PHP 4.2.0 under Linux.
------------------------------------------------------------------------
[2002-12-30 08:57:31] moriyoshi@php.net
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.
------------------------------------------------------------------------
[2002-12-30 08:45:08] moriyoshi@php.net
Verified. This is yet another "shallow copy" issue.
See http://bugs.php.net/20993
------------------------------------------------------------------------
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/21288
--
Edit this bug report at http://bugs.php.net/?id=21288&edit=1