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 8126977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:21:08+00:00 2026-06-06T07:21:08+00:00

If an object in PHP is stored in the session, $_SESSION , when will

  • 0

If an object in PHP is stored in the session, $_SESSION, when will it’s __destruct method be called? I haven’t been able to find any clear answer in the manual. It does say that __destruct will be automatically called at the end of script execution, so my expectation is that it will be called regardless of it’s existence in $_SESSION.

Does this then mean that potentially __destruct will be called on every request for an object in the session?

Added:
Will the object be serialized before or after __destruct? Will modifications in __destruct be reflected in the next request?

  • 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-06T07:21:10+00:00Added an answer on June 6, 2026 at 7:21 am

    You don’t actually store an object in session, you store it serialized as a string. You can then override the magic __sleep and __wakeup methods on the object. __sleep gets called when an object is serialized and __wakeup will be called when you attempt to unserialize an object.

    For more info, see:

    Manual Documentation for __sleep and __wakeup

    Manual Documentation for Storing Serialized Objects in Session

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

Sidebar

Related Questions

How to find memory used by an object in PHP? (c's sizeof). The object
I have an object, and I am using php's session to persist the objects
I created an object from PHP with json encode, but I am having difficulty
I'm writing an object in PHP that displays files on an FTP server. I
i created a model object in PHP class User { public $title; public function
I am new to Object Oriented PHP. Currently I am making a login script
I recently started with PHP Object Oriented and I cannot seem to get this
Goal: json_encode a PHP object that has private properties Send the encoded object as
I was playing with the DateTime object in PHP 5.3 on my local machine
I'm just starting with Object Oriented PHP and I have the following issue: I

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.