#18842 [Opn->Bgs]: cloning functions improperly, creates references and not copies
| From: | wez@php.net | Date: | Sat, 10 Aug 2002 11:23:59 +0000 |
| Subject: | #18842 [Opn->Bgs]: cloning functions improperly, creates references and not copies | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16427@lists.php.net to get a copy of this message | ||
ID: 18842
Updated by: wez@php.net
Reported By: ben-bugs.php.net@efros.com
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: linux
PHP Version: 4CVS-2002-08-10
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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