ID: 26794
Comment by: davidc at blesys dot com
Reported By: alex_boyer at hotmail dot com
Status: Verified
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2004-01-11
New Comment:
Ah, I see. $that is the old one.
I have an ugly solution:a = $that->a;
}
}
class B extends A {
public $b;
function __clone($thatj=''){
if ( $thatj != '' )$that=$thatj;
parent::__clone($that);
$this->b = $that->b;
}
}
$b = new B();
$b->a = 'AAA';
$b->b = 'BBB';
$clone = $b->__clone();
print_r($clone);
?>
Previous Comments:
[2004-01-11 22:34:21] davidc at blesys dot com
Sorry, I don't understand. Is $that a new feature of PHP5?
[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