note 24399 added to language.variables.scope
| From: | jpgiot at ifrance dot com | Date: | Thu, 15 Aug 2002 10:12:40 +0000 |
| Subject: | note 24399 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35058@lists.php.net to get a copy of this message | ||
when you want to access a variable in nested functions, don't forget that each function depend
of local scope, not main scope.
this don't work
$hello = 'hello';
function a()
{
function b()
{
global $hello;
echo $hello;
}
b();
}
but this works
$hello = 'hello';
function a()
{
global $hello; // here it is
function b()
{
global $hello;
echo $hello;
}
b();
}
and don't forget to declare your variable before using them with global inside a function
--
http://www.php.net/manual/en/language.variables.scope.php
http://master.php.net/manage/user-notes.php?action=edit+24399
http://master.php.net/manage/user-notes.php?action=delete+24399
http://master.php.net/manage/user-notes.php?action=reject+24399