Re: [RFC] Clone with v2
| From: | Tim Düsterhus | Date: | Wed, 14 May 2025 21:00:01 +0000 |
| Subject: | Re: [RFC] Clone with v2 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127362@lists.php.net to get a copy of this message | ||
Hi
Am 2025-05-14 22:06, schrieb Matthew Weier O'Phinney:
The only question that arose for me is: what happens if a property name is
provided to clone() that does not exist in the class definition; what
will be the behavior at that time? Will an exception or error be thrown? If
so, will it be a new one, or an existing one?
It's mentioned in the "Technical details" section:
Property assignments are made just as a regular assignment would beIt literally goes through the same code path. Thus a dynamic property will be created (and the associated warnings triggered). You can also see that in test
Zend/tests/clone/clone_with_002.phpt of the implementation:
Deprecated: Creation of dynamic property C::$c is deprecated in %s on line %dThe internal implementation is roughly equivalent to:
$cloned = clone $object;
foreach ($withProperties as $key => $value) {
$cloned->{$key} = $value;
}
return $cloned;
Just with the exception that writing readonly properties is allowed on the clone (unless already touched by __clone()).
Best regards
Tim Düsterhus