note 50027 rejected from reserved.variables by nlopess
| From: | nlopess@php.net | Date: | Wed, 16 Feb 2005 20:08:42 +0000 |
| Subject: | note 50027 rejected from reserved.variables by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-85137@lists.php.net to get a copy of this message | ||
Note Submitter: philip dot coombes at zoneminder dot com
----
I've come across a bit of a nasty with globals vs superglobals.
I've got some scripts that try and be friendly to older versions of php as well as new ones. So
I've got this code
<?php
if ( version_compare( phpversion(), "4.1.0", "<") )
{
$_SERVER = &$HTTP_SERVER_VARS;
$_SESSION = &$HTTP_SESSION_VARS;
}
?>
so that I can use $_SESSION everywhere. I think this is probably not the best solution but it was
what I used.
However in trying to debug a problem I found a couple of functions with
<?php
global $_SESSION;
?>
in. The globals are there to cover the case where $_SESSION is a reference and not a superglobal.
This appears to work under 4.3.8 and not work under 4.3.4 where 'work' is defined as just
being a redundant declaration that doesn't break anything. In 4.3.4 it imports the global
definition of $_SESSION but any modifications are lost when you leave the scope.
Anyone one know what it's supposed to do?