#47587 [Csd]: When exactly is __clone() executed?
| From: | scout at hyperspace-travel dot de | Date: | Fri, 06 Mar 2009 15:47:48 +0000 |
| Subject: | #47587 [Csd]: When exactly is __clone() executed? | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1948@lists.php.net to get a copy of this message | ||
ID: 47587
User updated by: scout at hyperspace-travel dot de
Reported By: scout at hyperspace-travel dot de
Status: Closed
Bug Type: Documentation problem
PHP Version: Irrelevant
New Comment:
Thank you!
Previous Comments:
------------------------------------------------------------------------
[2009-03-06 15:24:57] rquadling@php.net
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.
------------------------------------------------------------------------
[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."
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/47587
--
Edit this bug report at http://bugs.php.net/?id=47587&edit=1