1

I have the following code in an existing application:

if(!($article = $this->memcached->get('article_'.$articleId))) {
    $article = $this->model->ArticleManager()->getStoryById($articleId);
    $this->memcached->set('article_'.$articleId, $article);
}

No, when $article is retrieved from the ArticleManager it's of the correct type, it's a namespaced object \Site\Articles\Article() to be exact. However, when this value is stored in memcached and returned on the next page load the object is of type __PHP_Incomplete_Class. Which I know means it can't find the original class, but why...?

The file this call is in is under the namespace \Site\index\default_Read_Controller().

3
  • 2
    Because you haven't included the class specification specifically for that 2nd request, and there isn't an autoload defined which can find it. (The class definition is not stored with the object data, you need to have that loaded or autoloadable on retrieval). Commented Oct 15, 2013 at 0:40
  • @Wrikken: it's an answer Commented Oct 15, 2013 at 0:47
  • Ah yes, was not that dedicated yesterday. I'll upgrade it to one. Commented Oct 15, 2013 at 7:42

1 Answer 1

2

Because you haven't included the class specification specifically for that 2nd request, and there isn't an __autoload (or a preferred spl_autoload_register()) defined which can find it. The class definition is not stored with the object data, you need to have that loaded or autoloadable on retrieval, or defined explicitly: see the remarks at unserialize(which is the function variables usually go through if stored outside the php request):

It's possible to set a callback-function which will be called, if an undefined class should be instantiated during unserializing. (to prevent getting an incomplete object "__PHP_Incomplete_Class".) Use your php.ini, ini_set() or .htaccess to define 'unserialize_callback_func'. Everytime an undefined class should be instantiated, it'll be called. To disable this feature just empty this setting.

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.