note 20127 added to language.variables.external
| From: | bishop at php2 dot chek dot com | Date: | Sat, 23 Mar 2002 01:57:47 +0000 |
| Subject: | note 20127 added to language.variables.external | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28112@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/language.variables.external.php
http://master.php.net/manage/user-notes.php?action=edit+20127
http://master.php.net/manage/user-notes.php?action=delete+20127
http://master.php.net/manage/user-notes.php?action=reject+20127