PHP Superglobals Hack

I’ve added my superglobals hack to tasks. The code looks like this:

This file (superglobals.inc.php) is included in each function that references a superglobal:

<?php
// for PHP versions < 4.1, will use the // vars defined in compatibility.inc.php if (!$_REQUEST || !$_SESSION || !$_SERVER || !$_COOKIE) { global $_REQUEST, $_SESSION, $_SERVER, $_COOKIE; } ?>

The superglobals are defined in another file (compatibility.inc.php) which is included at the top of the rendering pages:

<?php
if (!$_REQUEST) {
$_REQUEST = $HTTP_GET_VARS;
$_REQUEST = array_merge($_REQUEST, $HTTP_POST_VARS);
$_REQUEST = array_merge($_REQUEST, $HTTP_COOKIE_VARS);
}
if (!$_SESSION) {
$_SESSION = $HTTP_SESSION_VARS;
}
if (!$_SERVER) {
$_SERVER = $HTTP_SERVER_VARS;
}
if (!$_COOKIE) {
$_COOKIE = $HTTP_COOKIE_VARS;
}
?>

You can include the $_POST, $_GET and $_FILES vars (etc.) if you use them.

This all seems to work, if you know of a problem with this technique, post a comment or let me know