2

Just for curiosity. All superglobals (for example $_POST, $_GET, $_FILES, $_SESSION) have an underscore and only the $GLOBALS superglobal does not. Why is that so? What does the underscore mean in superglobal variables in PHP and generaly in PHP? Thanks in advance.

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
Branko Sego
  • 780
  • 6
  • 13
  • 1
    It's a good question, but it's probably for the same reason that PHP has so many other quirky features, like the ability to parse `$foo = bar;` with nothing more than a Notice. – Niet the Dark Absol Sep 07 '14 at 10:32

2 Answers2

4

I saw a note on PHP manual page that says

Note: Variable availability Unlike all of the other superglobals, $GLOBALS has essentially always been available in PHP.

May be that's why they want to keep it like this, but this is just a guess.

http://php.net/manual/en/reserved.variables.globals.php

Bilal
  • 2,645
  • 3
  • 28
  • 40
2

Previously, $_POST was referred to as $HTTP_POST_VARS, and other superglobals were similarly named.

It's entirely likely that $_POST was chosen because the practice of writing $POST = &$HTTP_POST_VARS; was significantly high back in PHP 4, so the underscore is there to prevent breaking that old code.

Of course, this is just a guess!

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Interesting guess, I haven't really thought about that. If you have any sources that would be amazing, for now I will upvote. ;) – Branko Sego Sep 07 '14 at 10:40