note 45879 deleted from language.oop5.cloning by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 22 Sep 2004 19:30:04 +0000 |
| Subject: | note 45879 deleted from language.oop5.cloning by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77183@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I found that cloning of objects is a subtle pitfall if you have extensively used OOP in PHP4 and
have to migrate to PHP5. A simple equality sign creates a reference in PHP5, not a copy, what it
does in PHP4. At least this is a where PHP5 is not backwards compatible with PHP4. I.Schramm,
Ister.ORG
<?php
//PHP4
$objcopy4 = $object;
$objref4 =& $object;
//PHP5
$objcopy5 = clone $object;
$objref5 = $object;
//in conclusion, if you run the following with PHP5
$objcopy4->add(1);
//$result becomes true, not false like in PHP4
$result = ($objcopy4 == $object);
?>