note 92868 added to language.variables.scope
| From: | StephenDewey at osu1 dot php dot net | Date: | Wed, 12 Aug 2009 15:06:29 +0000 |
| Subject: | note 92868 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159369@lists.php.net to get a copy of this message | ||
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');
?>
----
Server IP: 69.147.83.197
Probable Submitter: 65.46.73.222
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/92868
Del: integrated -- https://master.php.net/note/delete/92868/integrated
Del: useless -- https://master.php.net/note/delete/92868/useless
Del: bad code -- https://master.php.net/note/delete/92868/bad+code
Del: spam -- https://master.php.net/note/delete/92868/spam
Del: non-english -- https://master.php.net/note/delete/92868/non-english
Del: in docs -- https://master.php.net/note/delete/92868/in+docs
Del: other reasons-- https://master.php.net/note/delete/92868
Reject -- https://master.php.net/note/reject/92868
Search -- https://master.php.net/manage/user-notes.php