note 20127 deleted from language.variables.external by didou
| From: | didou@php.net | Date: | Wed, 21 Jan 2004 09:30:01 +0000 |
| Subject: | note 20127 deleted from language.variables.external by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63934@lists.php.net to get a copy of this message | ||
Note Submitter: bishop
----
[Editors note: You may just want to use the older still existing predefined vars, like
$HTTP_GET_VARS, etc.]
Additional comments on <ojaswi@post.pl>, <darius@nomagiclt.com>, et. al.:
You can't refer to superglobals via variable variables inside of functions (see bug #15810), so
trying to put the earlier comments of <ojaswi@post.pl> in a function to register globals will
not work:
function register_globals_regardless() { // non-working version
if (!ini_get('register_globals')){
$__am = array('COOKIE','POST','GET');
while (list(,$__m) = each($__am)){
$__ah = &${"_".$__m};
if (!is_array($__ah)) continue;
while (list($__n, $__v) = each ($__ah)) $GLOBALS[$__n] = $__v;
}
}
}
A kludge until the feature in bug #15810 is added is:
function register_globals_regardless() {
if (!ini_get('register_globals')) {
$__am = array(&$_COOKIE, &$_POST, &$_GET);
while (list(,$__m) = each($__am)) {
if (is_array($__m)) {
$GLOBALS += $__m;
}
}
}
}
All the kludge function does is explicitly access the superglobals, rather than via variable
variables; it also uses references to cut down on copy time. Note the array_merge (the += business)
cleans up the code a little.
And if you really wanted to get down and dirty, you could just:
$GLOBALS += $_GET;
$GLOBALS += $_POST;
/* etc */
whenever you wanted to make sure you had your globals registered.