|
Posted by Wayne on 08/27/05 02:54
On Fri, 26 Aug 2005 16:50:00 -0400, "Kevin" <kevin@wxREMOVE4SPAM3.com>
wrote:
>PHP5 copies by reference by default, so this doesn't work--- I'm not
>modifying the copies, I'm modifying the original. I read about a trick to
>create a PHP4/PHP5 compatible clone function, but that doesn't work either.
>PHP5's clone is a shallow copy, so the properties of the original which are
>other objects only get referenced.
PHP5 automatically calls a function called __clone() during the
cloning process. This can be used to make deep clones of objects by
cloning all the object properties.
Example:
class Test {
function __clone() {
$this->property1 = clone($this->property1);
$this->property2 = clone($this->property2);
}
That might help.
Navigation:
[Reply to this message]
|