Tutorial by Examples

The scope outside of any function or class is the global scope. When a PHP script includes another (using include or require) the scope remains the same. If a script is included outside of any function or class, it's global variables are included in the same global scope, but if a script is include...
Superglobal variables are defined by PHP and can always be used from anywhere without the global keyword. <?php function getPostValue($key, $default = NULL) { // $_POST is a superglobal and can be used without // having to specify 'global $_POST;' if (isset($_POST[$key])) { ...
Static class properties that are defined with the public visibility are functionally the same as global variables. They can be accessed from anywhere the class is defined. class SomeClass { public static int $counter = 0; } // The static $counter variable can be read/written from anywhere...

Page 1 of 1