|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-09-02 21:24 UTC] stas@php.net
-Package: PHP Language Specification
+Package: Scripting Engine problem
[2015-09-02 21:37 UTC] requinix@php.net
[2016-03-27 16:23 UTC] nikic@php.net
-Status: Open
+Status: Wont fix
[2016-03-27 16:23 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
Description: ------------ It should works exactly like the `clone`, but with some features. // Usage. clone($user)->find(1); // Currently (too verbose): $userClone = clone $user; $userClone = $userClone->find(1); // __clone() reinforcement: callback that can // - get/set private/protected attributes or // call private/protected methods. clone($user, function ($baseObject) use ($externalData) { $this->privateAttribute = $baseObject->privateAttribute + $externalData; }); Signature (pseudo-code): function clone ($object, callable $callback = null) { assert(is_object($object)); if (!$callback) return clone $object; // __clone() is called here. $clone = clone $object; // Pass $clone as $this, and $object as first parameter. // Before call(), __clone() is called. $callback->call($clone, $object); return $clone; }