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

  • Home
  • SEARCH
  • 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 998505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:12:22+00:00 2026-05-16T07:12:22+00:00

Can anyone explain me, why in the session in this case we get the

  • 0

Can anyone explain me, why in the session in this case we get the object with 2 properties?

set_error_handler('my_error_handler');

session_start();

$obj = new myclass();

$_SESSION['obj'] = $obj;

$a->b();

class myclass
{
    private $a = 1;
    private $b = 2;

    public function __sleep()
    {
        return array('a');
    }
}

function my_error_handler($code, $error, $file = NULL, $line = NULL)
{
    throw new ErrorException($error, $code, 0, $file, $line);
}

UPD: here i expect to get:
1. fatal error (passed)
2. object in session (in session file) with 1 property (failed)

  • 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-05-16T07:12:22+00:00Added an answer on May 16, 2026 at 7:12 am

    The reason for this is that a fatal error is, well, fatal to the engine. After it, the engine cannot call anymore functions.

    Hence, in php_var_serialize_intern the call to __sleep fails. As you can see, you don’t need a fatal error, if __sleep had thrown an exception, or if there wasn’t any __sleep callback at all, the behavior would be similar.

    In particular, the behavior is to retrieve all the instance properties of the variable and to serialize the resulting hash table as if it belonged to an array.

    I think this is a valid approach, but perhaps you think that if the call to __sleep fails, the serialization should just fail. You can try to submit a feature request.

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

Sidebar

Related Questions

Can anyone explain to me why i get this error: Parse error: syntax error,
Can anyone explain why this jQuery .html() function is not outputting anything? I'm new
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone explain this code to me? Whats the meaning and how to use
Can anyone explain why this code: {% form_theme form _self %} {% block avo_gallery_upload_widget
Can anyone explain how to make this code work? echo '<div id=panel1-under>Welcome <?php echo
can anyone explain this to me?: if (isset($_SESSION['pack'])){ if (is_array($_SESSION['pack'])){ foreach ($_SESSION['pack'] as $pack){
Can anyone explain what this mod_rewrite rule is doing? I'm trying to comment the
I'm confused about the session states of SQL Server sessions. Can anyone explain it?
Can anyone explain why this example is thread safe without volatile? http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html In fact,

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.