Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:13:05+00:00 2026-06-03T23:13:05+00:00

Is there anything problematic in simply setting $GLOBALS to be an empty array? I

  • 0

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

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

For information, the FAQ at http://www.php.net/manual/en/faq.misc.php#faq.misc.registerglobals has the following to emulate register_globals = 0:

<?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) && is_array($_SESSION) ? $_SESSION : array());

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

unregister_GLOBALS();

?>

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

The question then is: is it bad to unset $GLOBALS['_GET'], $GLOBALS['_PUT'], etc. (“the variables that shouldn’t be unset” as the example states — is this really the case?)?

Update:

I’ve answered this myself below. Silly me for not trying earlier.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:13:06+00:00Added an answer on June 3, 2026 at 11:13 pm

    I’ve answered part of this myself. I was stupid for not trying earlier:

    $var = 'Hello, world!';
    
    unset($GLOBALS['var']);
    
    echo $var; // Notice: Undefined variable: var
    
    
    
    $var = 'Hello, world!';
    
    $GLOBALS = array();
    
    echo $var; // Hello, world!
    

    So simply setting $GLOBALS as an empty array won’t unset the global variables. They need to be explicitly unset.

    Update:

    Using unset($GLOBALS['_GET']); is the same as using unset($_GET) which is definitely not what I want. Question answered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anything more compact (or otherwise better) than this? <x:Array x:Key=titles Type=System:String> <System:String>Mr.</System:String>
Is there anything wrong with having a single class (one .h) implemented over multiple
Is there anything out there that can do what jsFiddle does, but for asp.net
Is there anything built in to determine if an XML file is valid. One
Is there anything wrong with setting a Rails variable inside a javascript function? I
Is there anything wrong with this html? I want to have a link in
Is there anything wrong with a union having one or more methods? Or anything
Is there anything in Python that works like the final keyword in Java -
Is there anything in Python akin to Java's JLS or C#'s spec?
is there anything built-in in Django templates that will allow me to compare two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.