You should be able to clone a object in compatibility of PHP4,PHP5 with:
<?php
$x=unserialize(serialize($y));
?>
downloads |
documentation |
faq |
getting help |
mailing lists |
reporting bugs |
php.net sites |
links |
conferences |
my php.net
In PHP 5 there is a new Object Model. PHP's handling of objects has been
completely rewritten, allowing for better performance and more features.
In previous versions of PHP, objects were handled like primitive types
(for instance integers and strings). The drawback of this method was that
semantically the whole object was copied when a variable was assigned, or
passed as a parameter to a method. In the new approach, objects are
referenced by handle, and not by value (one can think of a handle as an
object's identifier).
Many PHP programmers aren't even aware of the copying quirks of the old object model and, therefore, the majority of PHP applications will work out of the box, or with very few modifications. The new Object Model is documented at the Language Reference. In PHP 5, function with the name of a class is called as a constructor only if defined in the same class. In PHP 4, it is called also if defined in the parent class. See also the zend.ze1_compatibility_mode directive for compatability with PHP 4. New Object Model
zzo38
07-Oct-2007 08:06
You should be able to clone a object in compatibility of PHP4,PHP5 with:
bdas at premiergroup dot uk dot com
25-May-2007 07:49
Since PHP5 upgraded PHP to an OOP language, they CHANGED the metaphor so that when you copy an object, you just get a pointer to it (as in C# and Java) and so therefore they needed to make a way to CLONE objects as well in case you need a REAL copy of the object.
quinn at strangecode dot com
19-May-2006 08:53
Here is another possible solution for migrating code to php 5 when using $this = 'something' reassignments. In my case, I had several classes with methods that were self-instantiating with static calls. I was able to simply use a different variable: I changed $this to $_this and it worked the same because I copied an instance of the original object by reference using an instantiation factory method:
riseofthethorax at yahooo dot com
28-Sep-2005 06:53
I actually understand the addressing modes in 4.3 and use them, it hasn't bothered me.. Like I have objects within objects, each with variables containing references (like pointers but without the pointer arithmetic). I can obtain an object group from the database, obtain the method interface to a subobject, issue a manipulation through the child, then store the object group back into the database with the manipulation intact.. I'm not sure what effect the new changes will have on this, but if its drastic, I'm not sure I can support 5.0.
hairmare-spam at purplehaze dot ch
10-Jun-2005 04:41
I have noted some discussion going on about the 'Cannot re-assign $this' error.
ivanildo at kowsoleea.de
23-May-2005 02:56
It seems that simpleXML functions like 'simplexml_load_file' do not work in ze1 compatibility mode due to some cloning 'features' I do not yet understand.
Copyright © 2001-2007 The PHP Group
All rights reserved. |