note 29885 deleted from language.variables.scope by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:41:36 +0000 |
| Subject: | note 29885 deleted from language.variables.scope by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155579@lists.php.net to get a copy of this message | ||
Note Submitter: pim at lingewoud dot nl
----
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
}