DDC-155: [2.0] ProxyFactory generates two __sleep methods() #192

Closed
opened 2026-01-22 12:30:10 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 17, 2009).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user reinier.kip:

The proxy factory seems to generate two *_sleep methods if the parent class also implements __sleep: one by _generateMethods and one by *generateSleep.

Originally created by @doctrinebot on GitHub (Nov 17, 2009). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user reinier.kip: The proxy factory seems to generate two *_sleep methods if the parent class also implements __sleep: one by _generateMethods and one by *generateSleep.
admin added the Bug label 2026-01-22 12:30:10 +01:00
admin closed this issue 2026-01-22 12:30:10 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 17, 2009):

Comment created by romanb:

Note that if you use __sleep/__wakeup in your entities you should better implement Serializable instead. We're working on removing the no-arg constructor requirement and this has consequences on __wakeup.

See DDC-79 for details.

@doctrinebot commented on GitHub (Nov 17, 2009): Comment created by romanb: Note that if you use __sleep/__wakeup in your entities you should better implement Serializable instead. We're working on removing the no-arg constructor requirement and this has consequences on __wakeup. See [DDC-79](http://www.doctrine-project.org/jira/browse/DDC-79) for details.
Author
Owner

@doctrinebot commented on GitHub (Nov 17, 2009):

Comment created by reinier.kip:

Ah yes, DDC-79. Very interesting improvement. Thanks for the hint on the Serializable.

@doctrinebot commented on GitHub (Nov 17, 2009): Comment created by reinier.kip: Ah yes, [DDC-79](http://www.doctrine-project.org/jira/browse/DDC-79). Very interesting improvement. Thanks for the hint on the Serializable.
Author
Owner

@doctrinebot commented on GitHub (Dec 8, 2009):

Comment created by @beberlei:

What should we do about this issue.

@doctrinebot commented on GitHub (Dec 8, 2009): Comment created by @beberlei: What should we do about this issue.
Author
Owner

@doctrinebot commented on GitHub (Dec 17, 2009):

Comment created by romanb:

_generateMethods should probably skip the __sleep method?

@doctrinebot commented on GitHub (Dec 17, 2009): Comment created by romanb: _generateMethods should probably skip the __sleep method?
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Comment created by reinier.kip:

_generateMethods should probably skip the __sleep method?
Yes. You already call parent::__sleep() in the _sleep method generated by __generateSleep. Any consequences you have in mind?

Is the consequence on __wakeup that __wakeup can't rely on its properties, as the object is still to be hydrated? What about unserializing with the properties in place? What other consequences are there?

The thing is that implementing Serializable is quite different than taking the __sleep/__wakeup approach. When using Serializable, PHP does not take care of circular references ($a->ref->ref === $a). This is expected behaviour and the implementer is expected to take care of this him- or herself. This is why, although I like an interface better than "magic methods", I prefer __sleep and __wakeup.

Please discuss.

@doctrinebot commented on GitHub (Jan 5, 2010): Comment created by reinier.kip: > _generateMethods should probably skip the __sleep method? > Yes. You already call parent::__sleep() in the _sleep method generated by __generateSleep. Any consequences you have in mind? Is the consequence on __wakeup that __wakeup can't rely on its properties, as the object is still to be hydrated? What about unserializing with the properties in place? What other consequences are there? The thing is that implementing Serializable is quite different than taking the __sleep/__wakeup approach. When using Serializable, PHP does not take care of circular references ($a->ref->ref === $a). This is expected behaviour and the implementer is expected to take care of this him- or herself. This is why, although I like an interface better than "magic methods", I prefer __sleep and __wakeup. Please discuss.
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2010):

Comment created by @beberlei:

Hm there are not really effects on **sleep, just on wakeup i guess.

**wakeup will be called by Doctrine soon, its probably just something you have to be aware of.

Nevertheless, I'll skip sleep in generateMethods, its a bug.

@doctrinebot commented on GitHub (Jan 6, 2010): Comment created by @beberlei: Hm there are not really effects on **sleep, just on wakeup i guess. **wakeup will be called by Doctrine soon, its probably just something you have to be aware of. Nevertheless, I'll skip sleep in generateMethods, its a bug.
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2010):

Comment created by @beberlei:

Fixed in trunk, sleep is skipped.

@doctrinebot commented on GitHub (Jan 6, 2010): Comment created by @beberlei: Fixed in trunk, sleep is skipped.
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 6, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#192