note 48570 added to language.variables.predefined
| From: | urbanheroes{at}gmail{dot}com at osu1 dot php dot net | Date: | Thu, 30 Dec 2004 00:17:44 +0000 |
| Subject: | note 48570 added to language.variables.predefined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82476@lists.php.net to get a copy of this message | ||
Note that llcooldanny's solution won't make those variables superglobal, so they still
can't be used in functions like normal. One solution is to use $GLOBALS["_GET"]
instead of $_GET or $HTTP_GET_VARS, which will work in both PHP version after 4.1.0, and in versions
before 4.1.0 if you use that solution:
<?php
if(version_compare(phpversion(), '4.1.0') == -1) {
$_POST = &$HTTP_POST_VARS;
$_GET = &$HTTP_GET_VARS;
$_COOKIE = &$HTTP_COOKIE_VARS;
$_REQUEST = array_merge($HTTP_COOKIE_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS);
}
// In the global scope, they can be used normally in any version:
var_dump($_GET);
function dump_get() {
// This won't work in versions less than PHP 4.1.0, even using the above solution:
var_dump($_GET);
// This, however, will work in any version:
var_dump($GLOBALS["_GET"]);
}
dump_get();
?>
If you plan to have full backwards- and forwards-compatibility, you can use that solution and the
$GLOBALS["_GET"] syntax in place of a check for $HTTP_GET_VARS or $_GET when using
superglobals in functions.
----
Manual Page -- http://www.php.net/manual/en/language.variables.predefined.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48570
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48570&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48570&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48570&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48570&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48570&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48570&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48570&report=yes
Search -- http://master.php.net/manage/user-notes.php