Symfony2 – ErrorException: Notice: serialize() [function.serialize]: “xxx” returned as member variable from __sleep() but does not exist in …

While storing an entity from Doctrine2 in the session under a Symfony2 application I got this error:

ErrorException: Notice: serialize() [function.serialize]: "entity_property" returned as member variable from __sleep() but does not exist in ...vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php line 27

This error was happening because my “entity_property” was declared as private and PHP has some issues serializing objects that subclass a class with private properties. Just changing that “entity_property” to protected (as it should always have been…) solver the error.

Ref: http://blog.geertvd.be/2011/09/25/symfony2-id-returned-as-member-variable-from-__sleep-but-does-not-exist

You might also like

Fix “Cannot redeclare class Symfony…” in Symfony2 after upgrade
After upgrading from Symfony 2.2 to 2.3 I got this error in my application:Fatal error: Cannot redeclare...

Fix “Class ‘PMA_Message’ not found” in phpMyAdmin with nginx + PHP_FPM
After updating phpMyAdmin I got this error:PHP message: PHP Fatal error: Class 'PMA_Message' not...

Symfony2 routing: Allow dots in URL
I have one route in my app that must have a text and a dot followed by a format. For example:http://domain.com/image/mi-text-with-dots-.-in-.-the-.-middle.pngAs...

Fix The parameter “debug.error_handler.throw_at” must be defined in Symfony2
If you get this error when trying to clear a Symfony2 application cache:$ php app/console cache:clear...

  1. i had the same problem, and solved it by implementing in my entity, besides UserInterface, the Serializable interface. You need to provide the Serialize() and Unserialize() methods that Serializable interface requires. I spent 4 days in this, i had no internet.
    see ya

    • Thanks! I also spent a lot of time with this error. I’ll check your solution next time.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.