#47587 [Bgs->Csd]: When exactly is __clone() executed?
| From: | rquadling@php.net | Date: | Fri, 06 Mar 2009 15:24:57 +0000 |
| Subject: | #47587 [Bgs->Csd]: When exactly is __clone() executed? | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1947@lists.php.net to get a copy of this message | ||
ID: 47587
Updated by: rquadling@php.net
Reported By: scout at hyperspace-travel dot de
-Status: Bogus
+Status: Closed
Bug Type: Documentation problem
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Text changed to:
When an object is cloned, PHP 5 will perform a shallow copy of all of
the object's properties. Any properties that are references to other
variables, will remain references.
Once the cloning is complete, if a __clone() method is defined, then
the newly created object's __clone() method will be called, to allow
any necessary properties that need to be changed.
Previous Comments:
------------------------------------------------------------------------
[2009-03-06 15:16:25] scout at hyperspace-travel dot de
I'd propose the following little alteration.
"When an object is cloned, PHP 5 will perform a shallow copy of all
of the object's properties. Any properties that are references to
other variables, will remain references.
If a __clone() method is defined, the newly created object's
__clone() method will be called after the shallow copy, to allow any
necessary properties that need to be changed."
I understood the "then" in "If... then" as a causal correlation, not as
indicating a sequence of operations. It IS an ambiguous formulation,
after all.
------------------------------------------------------------------------
[2009-03-06 14:59:27] rquadling@php.net
Is this easier to read?
"When an object is cloned, PHP 5 will perform a shallow copy of all
of the object's properties. Any properties that are references to
other variables, will remain references.
If a __clone() method is defined, then the newly created object's
__clone() method will be called, to allow any necessary properties
that need to be changed."
I read this as ...
Clone runs on the copied object, which has had a shallow copy run
against the original object.
------------------------------------------------------------------------
[2009-03-06 13:44:56] scout at hyperspace-travel dot de
"If a __clone() method is
defined, then the newly created object's __clone() method will be
called, to allow any necessary properties that need to be changed."
Yes, I read that. But that doesn't say WHEN __clone() is executed.
------------------------------------------------------------------------
[2009-03-06 13:34:39] rquadling@php.net
http://docs.php.net/manual/en/language.oop5.cloning.php
gives a clear
explanation of what happens when cloning is applied to an object.
"When an object is cloned, PHP 5 will perform a shallow copy of all
of the object's properties. Any properties that are references to
other variables, will remain references. If a __clone() method is
defined, then the newly created object's __clone() method will be
called, to allow any necessary properties that need to be changed."
------------------------------------------------------------------------
[2009-03-06 13:25:36] scout at hyperspace-travel dot de
Description:
------------
The documentation does not mention when exactly the __clone() method is
performed. Neither does any of the comments. No I figure it is done
AFTER shallow-copying the attributes of the old object to the new on, as
everything else would be braindead. But still, it would be nice to have
this information written down because that is a pretty crucial detail
and it helps to understand the process of cloning in the first place.
Greets, Lene
Reproduce code:
---------------
---
From manual page: language.oop5.cloning
---
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47587&edit=1