PHP: 'The script tried to execute a method or access a property of an incomplete object'

Have you ever got this error in PHP? I bet no, never.

Basically, it happens when you serialize an object of class A and try to unserialize it when class A doesn’t exist anymore.

How (the hell) do I get there?

If you are working with auto-generated proxy classes, store objects in the session and then clear your cache, once you retrieve an object from the session you are going to face it. A solution is to re-generate all the proxies before retrieving objects from the session1.

Notes
  1. in an ideal world, at every deployment you clear and re-generate proxies

In the mood for some more reading?

...or check the archives.