By: Emiley J. Emailed: 1728 times Printed: 2329 times
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.
Be the first one to add a comment
Most Viewed Articles (in PHP )
Most Emailed Articles (in PHP)