In your example, $foo is created as a variable in the global scope. (If your displayed script was included() from a different range of capabilities / methods.)
PHP has no real global variables. You must manually use it with the global $foo; operator global $foo; to access them. (In addition, “something global is bad” advises just that, advising badly.)
source share