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 be
It 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 %d
The 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