Bug #74862 [NEW]: Unable to clone instance when private __clone defined

From: Date: Thu, 06 Jul 2017 04:23:18 +0000
Subject: Bug #74862 [NEW]: Unable to clone instance when private __clone defined
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209837@lists.php.net to get a copy of this message
From: daniel at ciokix dot ro Operating system: Ubuntu 14.04 PHP version: 5.6.30 Package: Scripting Engine problem Bug Type: Bug Bug description:Unable to clone instance when private __clone defined Description: ------------ When defining the __clone magic method as private, the instance cannot be cloned from within the method implementing parent class. Test script: --------------- class a { private function __clone() { } private function __construct() { } public static function getInstance() { return new static(); } public function cloneIt() { $a = clone $this; return $a; } } class c extends a { } // private constructor $d = c::getInstance(); // private clone $e = $d->cloneIt(); Link to 3v4l: https://3v4l.org/bWr72 Expected result: ---------------- Expecting the same behavior as for __construct: a successfully cloned object. Actual result: -------------- The following misleading fatal error is thrown: Fatal error: Uncaught Error: Call to private c::__clone() from context 'a' which is not the case as clone is called from a context and not c. -- Edit bug report at https://bugs.php.net/bug.php?id=74862&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74862&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74862&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74862&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74862&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74862&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74862&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74862&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74862&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74862&r=support Expected behavior: https://bugs.php.net/fix.php?id=74862&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74862&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74862&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74862&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74862&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74862&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74862&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74862&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74862&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74862&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74862&r=mysqlcfg

« previous php.bugs (#209837) next »