5

I'm using CI and I have a UserModel that selects the user based on login information and sets a userVO and add this userVO in a session like this:

$this->session->set_userdata('user', $userVO);

When I try to access this session it return me this error:

Message: main() [function.main]: The script tried to execute a method 
or access a property of an incomplete object. Please ensure that the 
class definition "UserVO" 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.

I have found a "solution", I need CI to load the UserVO class before session class and it works.

The problem is that I have lots os VO classes and I'll need them inside the session and is a bad thing to autoload them because I won't need them all at the same time.

Is there any workaround?

Thanks in advance for any help.

2
  • 1
    I have lots os VO classes and I'll need them inside the session Sidenote: keep in mind that CI's sessions are cookies, so are limited to the 4Kb or so amount of space. Unless you're using the database, of course. Commented Jan 4, 2012 at 16:55
  • @DamienPirsy thanks for the tip but that won't be a problem =] Commented Jan 4, 2012 at 16:57

1 Answer 1

18

Whats going on is that you are saving an instance of the class to the session. In order to restore it, you first need to load the base class it is an instance of. You likely have lots of "instances" of the VO class, rather than lots of VO classes. You just need to load the file that has the class declaration.

The class instance really only contains what has changed from the base class, not the whole class. So it needs the underlying class to know what the "defaults" are.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I faced the same error message, the reason here was that APC apparently still held a copy of an object that has changed in the meantime. Clearing APC’s cache “fixed” the error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.