|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2004-02-03 13:51 UTC] andi@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
Description: ------------ In the following code __clone() have problems with member variables of type object ($this->obj is null). If the comment is removed from the call to __clone2() in __clone() then __clone2() also has problems with the vision. On the other hand __clone2() has no problems when called externally. The difference between the expected and the actual result is the second call to print_r() Reproduce code: --------------- <?php class clone_example { private $pub = 2; private $obj = NULL; function clone_example($obj) { $this->obj = $obj; } function __clone() { print_r($this); // $this->__clone2(); } function __clone2() { print_r($this); } } class fubar { public $v = array(1,2,3); } $fu = new fubar(); $a = new clone_example($fu); $a->__clone2(); $a->__clone(); $a->__clone2(); ?> Expected result: ---------------- clone_example Object ( [pub:private] => 2 [obj:private] => fubar Object ( [v] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ) clone_example Object ( [pub:private] => 2 [obj:private] => fubar Object ( [v] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ) clone_example Object ( [pub:private] => 2 [obj:private] => fubar Object ( [v] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ) Actual result: -------------- clone_example Object ( [pub:private] => 2 [obj:private] => fubar Object ( [v] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ) clone_example Object ( [pub:private] => 2 [obj:private] => ) clone_example Object ( [pub:private] => 2 [obj:private] => fubar Object ( [v] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) )