can any one please let me know the basic differences between
$GLOBALS["test"] and global $test
and, will it make sense that, if i use $GLOBALS["test"]
instead of $_SESSION['test']
?
can any one please let me know the basic differences between
$GLOBALS["test"] and global $test
and, will it make sense that, if i use $GLOBALS["test"]
instead of $_SESSION['test']
?
and, will it make sense that, if i use $GLOBALS["test"] instead of $_SESSION['test']?
No, session is different thing from a variable that is available globally.
$GLOBALS
An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.
http://php.net/manual/en/reserved.variables.globals.php
Explanation:
$GLOBALS
is an associative array available throughout your script, there is no need to use global $test
Note: This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods.
There is no difference between $GLOBALS["test"]
and global $test
. Both are pure evil and shouldn't be used.
$test
is supposed to store an information about something, let's say: number of balls. Everything is fine until there is such a variable and it store what it's suppose to store. However what happen if you decide to delete that variable or use it for other purpose? Bah, fatal errors pop out of nowhere! You don't know what's going on, everything worked fine, you just change a variable's value and everything is falling apart.