#18842 [Bgs]: cloning functions improperly, creates references and not copies
| From: | ben-bugs dot php dot net at efros dot com | Date: | Sat, 10 Aug 2002 15:58:55 +0000 |
| Subject: | #18842 [Bgs]: cloning functions improperly, creates references and not copies | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16449@lists.php.net to get a copy of this message | ||
ID: 18842
User updated by: ben-bugs.php.net@efros.com
Reported By: ben-bugs.php.net@efros.com
Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: linux
PHP Version: 4CVS-2002-08-10
New Comment:
Shouldn't "=" be a "copy / assign" operation and
"$var1=&$var2" be a
reference the original operation?
This change will break backward compatibility with existing php
applications, but more importantly it will confuse developers between
the differences of object copies and variable copies.
IMHO, I think this issue is being handled wrong. __clone() should be
called by default when assigning via "="
Previous Comments:
------------------------------------------------------------------------
[2002-08-10 07:23:58] wez@php.net
in ZE2:
$x = $y; // when is_object($y), make $x a reference to $y
$x = $y->__clone(); // make a copy of $y
It should say that in the Zend/ZEND_CHANGES file.
------------------------------------------------------------------------
[2002-08-10 02:21:49] ben-bugs.php.net@efros.com
I guess that if I explicitly call __clone(), everything goes okay. I
guess the problem is that it thinks I mean make reference when using
the "equals" assignment .... ?
------------------------------------------------------------------------
[2002-08-10 02:15:59] ben-bugs.php.net@efros.com
class tmp {
var $tmp = '';
function __construct($t) {
$this->tmp=$t;
}
}
$x = new tmp(4);
$y = $x;
echo "x = ".$x->tmp."<BR>\n"; /* prints 4 */
echo "y = ".(++$y->tmp)."<BR>\n"; /* prints 5 */
echo "x = ".$x->tmp."<BR>\n"; /* prints 5, but should be 4 still */
I guess the $y is still referencing the $x class ...
Also, if I create __clone(), it doesn't appear to execute.
This was tested on CVS 2002-8-8 SAPI and also 4.3.0 alpha 2 CLI
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18842&edit=1