note 92868 deleted from language.variables.scope by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:40:01 +0000 |
| Subject: | note 92868 deleted from language.variables.scope by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217932@lists.php.net to get a copy of this message | ||
Note Submitter: Stephen Dewey
----
For nested functions:
This is probably obvious to most people, but global always refers to the variable in the global (top
level) variable of that name, not just a variable in a higher-level scope. So this will not work:
<?php
// $var1 is not declared in the global scope
function a($var1){
function b(){
global $var1;
echo $var1; // there is no var1 in the global scope so nothing to echo
}
b();
}
a('hello');
?>