Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8612091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:32:29+00:00 2026-06-12T04:32:29+00:00

I have a problem with __sleep() function. This is the code I’m using. If

  • 0

I have a problem with __sleep() function.

This is the code I’m using. If I remove __sleep() function from class then everything works as expected.

class Test {
    private $name;

    function setName($value){
        $this->name = $value;
    }

    function getName(){
        return $this->name;
    }

    /* Works good without this function */
    public function __sleep() {
        echo 'Sleep';
    }
}

$obj = new Test;
$obj->setName('Juris');

apc_store('test', $obj);

$objAPC = apc_fetch('test');

// Output = Juris    
echo $obj->getName();
// No output and "Call to a member function getName() on a non-object" if __sleep() function is in class. Otherwise output = Juris
echo $objAPC->getName();

Why is this code not working? Are there any limitations with using APC and __sleep()?

PHP version: 5.3.14

APC version: 3.1.10

UPDATE from answer:

This will work if I change __sleep() function to this

public function __sleep() {
    return array('name');
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:32:31+00:00Added an answer on June 12, 2026 at 4:32 am

    The magic __sleep() method must return an array of property names that should be serialized, you’re returns nothing.

    Quoting from the manual (my emphasis):

    It can clean up the object and is supposed to return an array with the
    names of all variables of that object that should be serialized
    . If
    the method doesn’t return anything then NULL is serialized and
    E_NOTICE is issued.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with my query on C, I’m using the oci8 driver. This
i have a problem with deltaTime ive been using. My Code is the following:
I have problem with UIWebView delay when the load image from url. In my
So I have this test code to send HELLO over a USB serial port:
I have a block of code that runs within a TransactionScope and within this
I'm trying to understand how threads works. I have some examples from the school.
I have this following code fragment which is accessed by different threads. try {
Actually i have a problen while using progress dialog.The problem is not with the
I everyone. I currently have a problem with my focus when using a splash
So I have a very weird problem. I am writing some code in VB.Net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.