$GLOBALS = array();?
<p>Is there anything problematic in simply setting <code>$GLOBALS</code> to be an empty array? I want to reverse the effect of <code>register_globals</code> where it is turned on and one does not have access to the <code>.ini</code> file, but rather than iterate over each of the relevant super globals and unset where necessary, skipping such elements as <code>$GLOBALS['_POST']</code>, <code>$GLOBALS['_GET']</code>, etc. as is usually done, I wonder if it's OK to just remove them all.</p>

<p>Are there any problems that may arise from this? I don't ever plan to reference the <code>$GLOBALS</code> array as any variables that are to be scope-independent will either be set in the relevant super global (<code>$_GET</code>, <code>$_POST</code>, etc.) or will be stored as properties of a relevant registry class.</p>

<p>For information, the FAQ at <a href="http://www.php.net/manual/en/faq.misc.php#faq.misc.registerglobals" rel="nofollow">http://www.php.net/manual/en/faq.misc.php#faq.misc.registerglobals</a> has the following to emulate <code>register_globals = 0</code>:</p>

<pre><code>&lt;?php
// Emulate register_globals off
function unregister_GLOBALS()
{
    if (!ini_get('register_globals')) {
        return;
    }

    // Might want to change this perhaps to a nicer error
    if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
        die('GLOBALS overwrite attempt detected');
    }

    // Variables that shouldn't be unset
    $noUnset = array('GLOBALS',  '_GET',
                     '_POST',    '_COOKIE',
                     '_REQUEST', '_SERVER',
                     '_ENV',     '_FILES');

    $input = array_merge($_GET,    $_POST,
                         $_COOKIE, $_SERVER,
                         $_ENV,    $_FILES,
                         isset($_SESSION) &amp;&amp; is_array($_SESSION) ? $_SESSION : array());

    foreach ($input as $k =&gt; $v) {
        if (!in_array($k, $noUnset) &amp;&amp; isset($GLOBALS[$k])) {
            unset($GLOBALS[$k]);
        }
    }
}

unregister_GLOBALS();

?&gt;
</code></pre>

<p>Presumably performing <code>unset($GLOBALS[$k]);</code> does the same as performing <code>$GLOBALS = array();</code> except that the latter removes <em>everything</em> and involves only one line of code.</p>

<p>The question then is: is it bad to unset <code>$GLOBALS['_GET']</code>, <code>$GLOBALS['_PUT']</code>, etc. ("the variables that shouldn't be unset" as the example states -- is this really the case?)?</p>

<p><strong>Update:</strong></p>

<p>I've answered this myself below. Silly me for not trying earlier.</p>
