#26794 [Ver->Csd]: $that not available in parent class
| From: | andi@php.net | Date: | Tue, 03 Feb 2004 18:43:59 +0000 |
| Subject: | #26794 [Ver->Csd]: $that not available in parent class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54344@lists.php.net to get a copy of this message | ||
ID: 26794
Updated by: andi@php.net
Reported By: alex_boyer at hotmail dot com
-Status: Verified
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2004-01-11
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
The mechanism of __clone() was changed to solve such problems.
To clone an object you should now use clone $obj;
It will create a replica of $obj and call $replica->__clone() if
available. No more need for $that because you have all the info
replicated already
Calling the parent __clone() can be done by doing parent::__clone()
Previous Comments:
------------------------------------------------------------------------
[2004-01-05 09:20:05] alex_boyer at hotmail dot com
i mean that $that is not available in parent class A (but IT IS
available in class B)
------------------------------------------------------------------------
[2004-01-05 09:17:14] alex_boyer at hotmail dot com
Description:
------------
$that is not available in parent class B (uncomment code in class A you
will see it). So it is not possible to clone class in a recursive
way.
Reproduce code:
---------------
class A {
public $a;
function __clone(){
//if( $that === null ) die('$that is null');
$this->a = $that->a;
}
}
class B extends A {
public $b;
function __clone(){
parent::__clone();
$this->b = $that->b;
}
}
$b = new B();
$b->a = 'AAA';
$b->b = 'BBB';
$clone = $b->__clone();
print_r($clone);
Expected result:
----------------
B Object
(
[b] => BBB
[a] => AAA
)
Actual result:
--------------
B Object
(
[b] => BBB
[a] =>
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26794&edit=1