Programming Tutorials

superglobals in PHP

By: Emiley J. in PHP Tutorials on 2008-11-21  

As a general rule, PHP does not support global variables (variables that can automatically be accessed from any scope). However, certain special internal variables behave like global variables similar to other languages. These variables are called superglobals and are predefined by PHP for you to use. Some examples of these superglobals are

. $_GET[]. An array that includes all the GET variables that PHP received from the client browser.

. $_POST[]. An array that includes all the POST variables that PHP received from the client browser.

. $_COOKIE[]. An array that includes all the cookies that PHP received from the client browser.

. $_ENV[]. An array with the environment variables.

. $_SERVER[]. An array with the values of the web-server variables.

On a language level, it is important to know that you can access these variables anywhere in your script whether function, method, or global scope. You don't have to use the $GLOBALS[] array, which allows for accessing global variables without having to predeclare them or using the deprecated globals keyword.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)