What does the global keyword do if it is not used in the scope of a function?
What does the global
keyword do if it is not used in the scope of a function (file is not included from inside a function)
<?php
error_reporting(E_ALL);
$a=1;
global $a;
echo $a;
?>
Using global keyword outside a function is not an error. [Tick]
It can be used if the file is included from inside a function. [Tick开发者_JAVA技巧]
But what does the global keyword do when it is used in a "global file" (file that is not included from inside a function) ?
From http://php.net/manual/en/language.variables.scope.php :
Using global keyword outside a function is not an error. It can be used if the file is included from inside a function.
精彩评论