|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-07-06 06:36 UTC] spam2 at rhsoft dot net
[2017-10-05 11:09 UTC] nikic@php.net
-Status: Open
+Status: Verified
-PHP Version: 5.6.30
+PHP Version: 7.0.24
[2017-11-15 22:02 UTC] nikic@php.net
[2017-11-15 22:02 UTC] nikic@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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.