ID: 49987 Updated by: [email protected] Reported By: queenzeal at gmail dot com -Status: Open +Status: Bogus Bug Type: Feature/Change Request PHP Version: 5.3.0 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Calling $obj->__clone(); would work on the $obj instance which won't be the usual aim. Calling $obj->__toString() is fine to work on the $obj instance. Previous Comments: ------------------------------------------------------------------------ [2009-10-24 20:43:03] queenzeal at gmail dot com Description: ------------ __toString() can be called directly but __clone() cannot. It seems like this behavior ought to be consistent. Either both can be called directly or neither can be called directly. __clone()'s current behavior is documented in <http://php.net/language.oop5.cloning> with the following: "An object's __clone() method cannot be called directly." The only reason I can figure for that is that without it, it'd be possible to clone a cloned object redundantly. eg. $a = clone $b->__clone(). That said, it seems to me like this can be done, already, with $a = clone clone $b, so that seems like a non-issue. Reproduce code: --------------- class a { function __toString() { return 'a'; } function __clone() { return this; } } $a = new a(); echo "$a\r\n"; echo $a->__toString() . "\r\n"; $b = clone $a; $b = $a->__clone(); Expected result: ---------------- a a Actual result: -------------- Fatal error: Cannot call __clone() method on objects - use 'clone $obj' instead in C:\php\test.php on line 20 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49987&edit=1
