Is it still necessary to wrap the __clone implementation in an if check? #6524

Closed
opened 2026-01-22 15:34:30 +01:00 by admin · 1 comment
Owner

Originally created by @sirdiego on GitHub (Aug 24, 2020).

The documentation says that __clone (and __wakeup) are not save to implement without an id check. But the Instantiator has an isSafeToClone method that checks if there is an __clone method implemented. So is it still necessary to wrap the __clone into the id check?

Thanks!

Originally created by @sirdiego on GitHub (Aug 24, 2020). The [documentation](https://github.com/doctrine/orm/blob/2.7/docs/en/cookbook/implementing-wakeup-or-clone.rst) says that __clone (and __wakeup) are not save to implement without an id check. But the Instantiator has an [isSafeToClone](https://github.com/doctrine/instantiator/blob/1.3.x/src/Doctrine/Instantiator/Instantiator.php#L197) method that checks if there is an __clone method implemented. So is it still necessary to wrap the __clone into the id check? Thanks!
admin closed this issue 2026-01-22 15:34:30 +01:00
Author
Owner

@beberlei commented on GitHub (Sep 13, 2020):

@sirdiego No, its not necessary anymore, that was before ReflectionClass::newInstanceWithoutConstructor was added in PHP 5.4 or 5.5

@beberlei commented on GitHub (Sep 13, 2020): @sirdiego No, its not necessary anymore, that was before `ReflectionClass::newInstanceWithoutConstructor` was added in PHP 5.4 or 5.5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6524