|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46451 Session module needs a hook into the evaluator
Submitted: 2008-11-01 14:19 UTC Modified: 2020-11-16 16:24 UTC
Avg. Score:3.5 ± 1.4
Reproduced:3 of 4 (75.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jost_boekemeier at yahoo dot de Assigned:
Status: Analyzed Package: Session related
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
30 + 41 = ?
Subscribe to this entry?

 [2008-11-01 14:19 UTC] jost_boekemeier at yahoo dot de
If a PHP object is stored into the PHP session, __destruct() is called before __sleep().

One way to fix this bug is to change the evaluator to call session_write_close() before calling __destruct().

Reproduce code:
  * Check if __destruct() is called after __sleep()
  * exit with 1 if the test failed.
class C {
  var $destroyed = false;
  function __destruct() {
    echo "destroy called\n";
    $this->destroyed = true;
  function __sleep() {
    if ($this->destroyed) {echo("sleep failed. bleh!\n"); exit(1); }
    return array();
  function __wakeup() {
    $this->destroyed = false;
  function __toString() {
    return "C::".($this->destroyed?"destroyed":"active");
if(!$a) {
  echo "new C\n";
  $a=new C();
echo "$a\n";
exit (0);

Expected result:
result code 0

Actual result:
result code 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-23 21:27 UTC]
-Package: Feature/Change Request +Package: Session related -PHP Version: 5.2.6 +PHP Version: *
 [2013-06-27 11:00 UTC]
-Status: Open +Status: Analyzed -Package: Session related +Package: Scripting Engine problem
 [2013-06-27 11:00 UTC]
Verified with PHP 5.4/5.5.

This is not a session problem, but a scripting engine.

__destruct() should be the last magic method to be called at shutdown. Is there 
any good reason for this behavior?
 [2020-11-16 16:24 UTC]
-Package: Scripting Engine problem +Package: Session related
 [2020-11-16 16:24 UTC]
> __destruct() should be the last magic method to be called at
> shutdown. Is there any good reason for this behavior?

The early calling of all destructors during request shutdown[1] has
been introduced to fix bug #30578.  It seems to me that the session
module should call php_session_save_current_state() earlier than in
its request shutdown handler.

[1] <>
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Oct 07 10:05:52 2022 UTC