开发者

What does the global keyword do if it is not used in the scope of a function?

开发者 https://www.devze.com 2023-04-10 12:40 出处:网络
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)

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;
?>
  1. Using global keyword outside a function is not an error. [Tick]

  2. It can be used if the file is included from inside a function. [Tick开发者_JAVA技巧]

  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号