__PHP_Incomplete_Class Object

Posted: July 21st, 2009 | Author: | Filed under: PHP | 3 Comments »

Just a quick note, as I could not find a satisfactory answer fast enough googling the web. I got a (not so) nice __PHP_Incomplete_Class Object notice the other day, happily programming until that moment. Such a notice indicates that somewhere (very likely in your session) a class has been unserialized that php does not know how to handle. This means that php knows which class the unserialized data should be, but cannot find the class declaration. It may happen using this type of code:

class SomeClass { ... }
$_SESSION['some_instance']; // which is a SomeClass assigned in some previous request

Depending on the implementation of the class, e.g. use of SPL, this will result in a __PHP_Incomplete_Class Object. To fix this, tell php what the class is/can do before unserializing, i.e. move session_start below the class declaration.

3 Comments on “__PHP_Incomplete_Class Object”

  1. 1 cheruvattil sabin said at 2:14 pm on October 30th, 2009:

    we can resolve this by giving a reference to the class which we are trying to unserialize.

    class TwitterTweets
    var $tweets;
    var $image;
    var $accName;
    function __construct($tweet, $name, $image)
    $this->tweets = $tweet;
    $this->image = $image;
    $this->accName = $name;
    // if we are not having any reference to that class, we need to provide it
    // $tweetRaw[‘tweets’] – serialized class
    $serTweetObj = unserialize($tweetRaw[‘tweets’]);

  2. 2 __PHP_Incomplete_Class said at 12:49 am on May 27th, 2010:

    A comfortable way to avoid this common mistake is using an Autoloader.

  3. 3 gerrit said at 9:09 am on May 27th, 2010:

    exactly. Important to remember to define this autoloader before starting the session!