[nycphp-talk] Incomplete Objects, Class Definitions and require_once
Michael B Allen
ioplex at gmail.com
Sun Aug 5 20:07:46 EDT 2007
On 8/5/07, Brent Baisley <brenttech at gmail.com> wrote:
> I've never seen that error message before, but I think I understand
> what it is saying. It sounds like you are employing a technique that
> is generally frowned upon because of it's dependencies and
> complexity. Did you inherit this code from someone else?
> Since it's complaining about objects loading before unserialize, I'm
> guessing you are passing serialized objects either through a session
> or directly through to other objects. An object is an instance of a
> class, you need to load the base class definition in order to create
> an instance of that class. What you are doing is passing an instance
> of a class without having the class loaded. The only way I know of
> doing this is by passing a serialized instance through a session.
> When it is unserialized, it doesn't have the base class available to
> restore the class object.
> So, you must load (include) the class file before you try to
> unserialize the instance of the class. Alternatively, you can create
> an __autoload function that will determine what file needs to be
> loaded in order to create an instance of the class to be created.
> This can generally be done by mapping the class name be called to the
> file that needs to be loaded. __autoload is generally used for
> dynamically loading classes so you don't load anything that you don't
> You may connect to the database 90% of the time, but why load the
> database class before you need to, since you may not need to.
> Hope that helps
Well I figured out what the problem was. I was putting an 'Auth'
object in the session. I made some changes to something that
invalidated the class definition of that object. As soon as I logged
out the Auth object in the session was reinstantiated and the error
went away. No big deal.
> On Aug 5, 2007, at 2:49 PM, Michael B Allen wrote:
> > Hi,
> > Every once in a while I run into this and it takes a few hours to
> > figure out what the right sequence of require_once statements are
> > required to wriggle out of it:
> > Notice: [...] The script tried to execute a method or access a
> > property of an incomplete object. Please ensure that the class
> > definition "Foo" of the object you are trying to operate on was loaded
> > _before_ unserialize() gets called or provide a __autoload() function
> > to load the class definition in [...]
> > Can someone explain to me what I need to know about how class
> > definitions are loaded so that I can make some sense of these errors?
> > It's not simply a matter of including the necessary file in the right
> > spot. Clearly there are other forces at work and I'd like to know what
> > they are.
> > Mike
More information about the talk