DDC-1186: Proxy Objects are incompatible with Serialization #1493

Closed
opened 2026-01-22 13:16:08 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 1, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user johannes:

Lazy-loading users is impossible atm if you want to serialize them at some point, and they are using private member variables.

My suggestion is to check whether the proxied class implements the Serializable interface, and in these cases instead of implementing a **sleep method, a serialize/unserialize method should be implemented instead.

Something like:

public function serialize()
{
    return serialize(array($this->*_isInitialized_*, parent::serialize()));
}

public function unserialize($str)
{
    list($this->*_initialized_*, $parentStr) = unserialize($str);
    parent::unserialize($parentStr);
}

At the moment, this makes Doctrine Proxy objects incompatible with the Symfony Security component, and if possible it should be fixed for the 2.1 release. If you need help on this, let me know.

Originally created by @doctrinebot on GitHub (Jun 1, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user johannes: Lazy-loading users is impossible atm if you want to serialize them at some point, and they are using private member variables. My suggestion is to check whether the proxied class implements the Serializable interface, and in these cases instead of implementing a **sleep method, a serialize/unserialize method should be implemented instead. Something like: ``` public function serialize() { return serialize(array($this->*_isInitialized_*, parent::serialize())); } public function unserialize($str) { list($this->*_initialized_*, $parentStr) = unserialize($str); parent::unserialize($parentStr); } ``` At the moment, this makes Doctrine Proxy objects incompatible with the Symfony Security component, and if possible it should be fixed for the 2.1 release. If you need help on this, let me know.
admin added the Bug label 2026-01-22 13:16:08 +01:00
admin closed this issue 2026-01-22 13:16:08 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 1, 2011):

Comment created by johannes:

Closing this, not sure what I was debugging there, the problem is a Symfony one :)

@doctrinebot commented on GitHub (Jun 1, 2011): Comment created by johannes: Closing this, not sure what I was debugging there, the problem is a Symfony one :)
Author
Owner

@doctrinebot commented on GitHub (Jun 1, 2011):

Issue was closed with resolution "Invalid"

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

No dependencies set.

Reference: doctrine/archived-orm#1493