Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Adding a Contact Form Working with Post Variables

Frank D
Frank D
14,042 Points

Why $_POST is all with capital letters?

I know it may be a silly question, but why the variable $_POST is all with capital letters?

2 Answers

Daniel Johnson
Daniel Johnson
104,132 Points

The all capital letters plus the beginning underscore just helps to identify $_POST as a superglobal which means you have access to the $_POST variables in all scopes throughout any of your scripts. The underscore also helps to not interfere with constants that may already exist in your scripts, which will use all capital letters as well.

Other superglobals include $GLOBALS, $_SERVER, $_GET, $_FILES, $_COOKIE, $_SESSION, $_REQUEST, and $_ENV. The reason why $GLOBALS does not include a underscore is because it has existed since PHP was first available, and at the time they did not originally use the underscore in combination with all capital letters. It also has the word global already in its name so it's kind of obvious what it is.

You can then access all the variables stored inside each one of these superglobals whenever you need. Checkout the PHP documentation on superglobals more information about these types of variables.

Frank D
Frank D
14,042 Points

This is extremely helpful!! Now it all make sense to me. Thank you for the PHP documentation link Daniel!!

Daniel Johnson
Daniel Johnson
104,132 Points

Glad to hear it all makes sense now. :)

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi Frank,

This is not a silly question at all. It's good to ask questions like this to deepen your understanding of a language.

Unlike normal variables that you assign yourself, PHP has some built-in variables that are always available in your script and in all scopes. These are called Superglobals (awesome name right?) and are predefined in PHP.

Superglobal variables have all capital letters in the variable name to differentiate them between normal variables and so that PHP knows you are calling a superglobal.

You might have come across some other Superglobals such as $_GET, $_SESSION, $_COOKIE and a few more. These are all Superglobal variables.

You might also have defined global variables before, where you define global $variable Well with Superglobals, they are already predefined as global, so you can use them anywhere in your script right off the cuff.

Hope this helps :D

Edit: Realised after finishing typing up my reply that Daniel Johnson wrote a good explanation of superglobals. His answer is spot on.

Frank D
Frank D
14,042 Points

Thank you for your kind help John, you both have been very helpful to me!! Cheers

John Steer-Fowler
John Steer-Fowler
Courses Plus Student 11,734 Points

Thats no problem. Keep up with the good work, and don't be hesitant to ask questions on the forum like this. It's one of the best ways to develop a really in-depth understanding of a language.