note 113114 added to reserved.variables.session
| From: | opajaap at opajaap dot nl | Date: | Sat, 31 Aug 2013 11:51:42 +0000 |
| Subject: | note 113114 added to reserved.variables.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196134@lists.php.net to get a copy of this message | ||
Be carefull with $_SESSION array elements when you have the same name as a normal global.
The following example leads to unpredictable behaviour of the $wppa array elements, some are updated
by normal code, some not, it is totally unpredictable what happens.
<?php
global $wppa;
$wppa = array( 'elm1' => 'value1', 'elm2' => 'value2',
....etc...);
if ( ! session_id() ) @ session_start();
if ( ! isset($_SESSION['wppa']) $_SESSION['wppa'] = array();
if ( ! isset($_SESSION['wppa']['album']) )
$_SESSION['wppa']['album'] = array();
$_SESSION['wppa']['album'][1234] = 1;
$wppa['elm1'] = 'newvalue1';
print_r($_SESSION);
?>
This will most likely display Array ( [wppa] => Array ( [album] => Array ( [1234] => 1 )
[elm1] => 'newvalue1' [elm2] => 'value2' ... etc ...
But setting $wppa['elm1'] to another value or referring to it gives unpredictable results,
maybe 'value1', or 'newvalue1'.
The most strange behaviour is that not all elements of $wppa[xx] show up as
$_SESSION['wppa'][xx].
----
Server IP: 69.147.83.199
Probable Submitter: 188.203.174.57
----
Manual Page -- http://php.net/manual/en/reserved.variables.session.php
Edit -- https://master.php.net/note/edit/113114
Del: integrated -- https://master.php.net/note/delete/113114/integrated
Del: useless -- https://master.php.net/note/delete/113114/useless
Del: bad code -- https://master.php.net/note/delete/113114/bad+code
Del: spam -- https://master.php.net/note/delete/113114/spam
Del: non-english -- https://master.php.net/note/delete/113114/non-english
Del: in docs -- https://master.php.net/note/delete/113114/in+docs
Del: other reasons-- https://master.php.net/note/delete/113114
Reject -- https://master.php.net/note/reject/113114
Search -- https://master.php.net/manage/user-notes.php