Objects inside $_SESSION, undocumented behaviour
Please have look on the following code:
$_SESSION["process_y"] = new Process();
$process_y = $_SESSION[开发者_运维问答"process_y"];
$process_y->name = "John";
$process_y = $_SESSION["process_y"];
echo " name is ".$process_y->name;
// Outputs "name is John"
I fetch an object from a SESSION variable. Then I modify a member of this object, but never saved it back to session. For some reason I'm not aware of, the modified object gets saved in the session like if the fetched object would be a "pointer".
I couldn't find any reference explaining this behaviour in php documentation.
NOTE: register_globals is OFF.
That behavior isn't undocumented and it has nothing to do with the global _SESSION-Array. In some way you are right: It's a pointer. Check the manual for full explanation: http://www.php.net/manual/en/language.oop5.references.php
As the $_SESSION variable is global, any mutations to it will be saved. In addition to that the $_SESSION spans over the individual requests (as a session should), so the behaviour is as expected.
精彩评论