note 71125 added to ref.session

From: Date: Mon, 13 Nov 2006 13:37:16 +0000
Subject: note 71125 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-119659@lists.php.net to get a copy of this message
There is a PROBLEM, mayby BUG with session $_SESSION. If you assign $_SESSION to variable you can'not register more data after assignment and it differs even on kind of variable. 1. NORMAL //From Session: print_r($_SESSION); $_SESSION["test1"] = "test1"; //$var = $_SESSION; //variable or self::$var = $_SESSION $_SESSION["test2"] = "test2"; //From Assignments: print_r($_SESSION); /* //Before reload page: //From Session obviously Nothing //From Asinments of course: Array ( [test1] => test1 [test2] => test2 ) //And after post page you get of course: //From Session Array ( [test1] => test1 [test2] => test2 ) //From Asinments of course: Array ( [test1] => test1 [test2] => test2 ) WRONG SOME BUGS - But if you assign $_SESSION to variable some sheet heppens: //self::$var = $_SESSION //static variable for ex. within some static method between sessions assignment; $_SESSION["test1"] = "test2..."; self::$var = $_SESSION $_SESSION["test2"] = "test2..."; //You get before: Array ( [test1] => test1 [test2] => test2 ) Array ( [test1] => test1... [test2] => test2... ) //And after reload Array ( [test1] => test1... // as you see only one variable was assign [test2] => test2 // - BUG ) Array ( [test1] => test1... [test2] => test2... ) //AND EVEN MORE strange things, if you assign local varaiable you cant change $_SESSION after and before: $_SESSION["test1"] = "test2............."; self::$var = $_SESSION $_SESSION["test2"] = "test2............."; //You get before: Array ( [test1] => test1... [test2] => test2 ) Array ( [test1] => test1.............. [test2] => test2.............. ) //And After Array ( [test1] => test1... //NOTHING WAS CHANGED [test2] => test2 ) Array ( [test1] => test1.............. [test2] => test2.............. ) I have a question: IS IT A BUG OR AM I DOIN'G SOMETHING WRONG ???? But i have found workaround, if somebody is interested; do cast to object when you assign like that: $var = (object)$_SESSION or self::$var = (object)$_SESSION ---- Server IP: 195.136.184.34 Probable Submitter: 62.87.153.116 ---- Manual Page -- http://www.php.net/manual/en/ref.session.php Edit -- https://master.php.net/note/edit/71125 Del: integrated -- https://master.php.net/note/delete/71125/integrated Del: useless -- https://master.php.net/note/delete/71125/useless Del: bad code -- https://master.php.net/note/delete/71125/bad+code Del: spam -- https://master.php.net/note/delete/71125/spam Del: non-english -- https://master.php.net/note/delete/71125/non-english Del: in docs -- https://master.php.net/note/delete/71125/in+docs Del: other reasons-- https://master.php.net/note/delete/71125 Reject -- https://master.php.net/note/reject/71125 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119659) next »