Edit report at https://bugs.php.net/bug.php?id=46451&edit=1
ID: 46451 Updated by: yohg...@php.net Reported by: jost_boekemeier at yahoo dot de Summary: Session module needs a hook into the evaluator -Status: Open +Status: Analyzed Type: Feature/Change Request -Package: Session related +Package: Scripting Engine problem Operating System: * PHP Version: * Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2008-11-01 14:19:04] jost_boekemeier at yahoo dot de Description: ------------ 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: --------------- <?php /** * 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"); } } session_id("session-write-close-bug"); session_start(); $a=@$_SESSION['a']; if(!$a) { echo "new C\n"; $a=new C(); $_SESSION['a']=$a; } $a=$_SESSION['a']; echo "$a\n"; //session_write_close(); exit (0); ?> Expected result: ---------------- result code 0 Actual result: -------------- result code 1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=46451&edit=1