|  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: 2013-06-27 11:00 UTC
Avg. Score:3.2 ± 1.3
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jost_boekemeier at yahoo dot de Assigned:
Status: Analyzed Package: Scripting Engine problem
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:
40 - 9 = ?
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?
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 22 13:01:24 2020 UTC