php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23280 exit; inside __wakeup() forgets changes to session vars
Submitted: 2003-04-19 12:08 UTC Modified: 2003-04-21 09:57 UTC
From: adamh at densi dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.0 OS: Linux 2.4.20
Private report: No CVE-ID: None
 [2003-04-19 12:08 UTC] adamh at densi dot com
<?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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-21 09:57 UTC] sniper@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 00:01:27 2024 UTC