note 29885 added to language.variables.scope
| From: | pim at lingewoud dot nl | Date: | Thu, 27 Feb 2003 17:46:19 +0000 |
| Subject: | note 29885 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44617@lists.php.net to get a copy of this message | ||
shevek wrote:
>> If you include a file from within a function using include(),
>> the included file inherits the function scope as its own
>> global scope, it will not be able to see top level globals
>> unless they are explicit in the function.
in addition:
if you define a function in that included file, it can't get the variables from the inluded
file's scope. global won't work. The only way to give such an include function access to
global vars is via arguments. I don't know if this is a bug in PHP.
//---- from within function included file -----
echo $var1; // this one works
function foo()
{
global $var1;
echo $var1; // this one doesn't
}
--
http://www.php.net/manual/en/language.variables.scope.php
http://master.php.net/manage/user-notes.php?action=edit+29885
http://master.php.net/manage/user-notes.php?action=delete+29885
http://master.php.net/manage/user-notes.php?action=reject+29885