#29441 [Bgs]: After copying a class, changes to new class affect old class.
| From: | php at cyruslesser dot com | Date: | Mon, 02 Aug 2004 12:21:09 +0000 |
| Subject: | #29441 [Bgs]: After copying a class, changes to new class affect old class. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-63935@lists.php.net to get a copy of this message | ||
ID: 29441
User updated by: php at cyruslesser dot com
Reported By: php at cyruslesser dot com
Status: Bogus
Bug Type: Class/Object related
Operating System: Linux Debian
PHP Version: 5.0.0
New Comment:
Well, in version 4.3.8, it returns
a: 1
b: 2
In version 5.0.0 it returns (without error or notification)
a: 2
b: 2
That may or may not be intentional, but if there's a way to copy an
object instead of a pointer to an object, I can't find it in the
manual.
Cyrus Lesser
Previous Comments:
------------------------------------------------------------------------
[2004-08-02 12:56:01] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
.
------------------------------------------------------------------------
[2004-07-29 08:44:27] php at cyruslesser dot com
Description:
------------
This may just be my mis-understanding of how the language should work,
but surely when you copy an object (class) and make changes to it,
those changes shouldn't affect the original object?
I don't really see the point in making a copy of an object, if the
changes you make to the new copy affect the old copy.
If I'm just dumb, then I apologise.
Reproduce code:
---------------
<?
class c {
var $i = 0;
};
$a = new c;
$a->i = 1;
$b = $a;
$b->i = 2;
echo "a: $a->i";
echo "b: $b->i";
?>
Expected result:
----------------
a: 1
b: 2
Actual result:
--------------
a: 2
b: 2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29441&edit=1