#23280 [NEW]: exit; inside __wakeup() forgets changes to session vars

From: Date: Sat, 19 Apr 2003 17:08:39 +0000
Subject: #23280 [NEW]: exit; inside __wakeup() forgets changes to session vars
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37908@lists.php.net to get a copy of this message
From: adamh at densi dot com Operating system: Linux 2.4.20 PHP version: 4.3.0 PHP Bug Type: Session related Bug description: exit; inside __wakeup() forgets changes to session vars <?php class MyObj { var $p1; function MyObj() { $this->p1 = "foo"; } function __sleep() { return array("p1"); } function __wakeup() { if (!isset($this->p1)) exit("No bug"); unset($this->p1); header("Location: " . $_SERVER["PHP_SELF"]); exit; } } session_start(); if (!isset($_SESSION["obj"]) || !isset($_SESSION["obj"]->p1)) { $_SESSION["obj"] =& new MyObj(); } var_dump($_SESSION["obj"]); ?> With the above code, the following "should" happen: 1. Browse to the page, it'll create the object and initialize p1, then var_dump() it. 2. Refresh. Through __wakeup(), p1 should be unset and then it should redirect. 3. (automatically redirected) __wakeup() should then run exit("No bug"); What DOES happen: In the second page, __wakeup() unsets p1 in a certain instance of the object, but that instance isn't the same as the one in $_SESSION["obj"]. Thus, the ACTUAL session object is not edited, and so we get an infinite redirect. The problem: It must be that if __wakeup() doesn't return the session is not updated. That's okay, I can live with that -- but at the very least, that behavior should be documented. On the other hand, as far as I know, it's a bug with PHP. -- Edit bug report at http://bugs.php.net/?id=23280&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=23280&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=23280&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=23280&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=23280&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=23280&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=23280&r=support Expected behavior: http://bugs.php.net/fix.php?id=23280&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=23280&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=23280&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=23280&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23280&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=23280&r=dst IIS Stability: http://bugs.php.net/fix.php?id=23280&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=23280&r=gnused

« previous php.bugs (#37908) next »