note 45879 added to language.oop5.cloning

From: Date: Wed, 22 Sep 2004 12:22:31 +0000
Subject: note 45879 added to language.oop5.cloning
Groups: php.notes 
Request: Send a blank email to php-notes+get-77148@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop5.cloning.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45879 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45879&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45879&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77148) next »