On Thu, 2007-01-18 at 10:29 -0500, tedd wrote:
> At 9:49 PM -0800 1/17/07, jekillen wrote:
> >Hello php list:
> >If I include a php script inside a php function definition and then call the
> >function in another script. What is the scope of variables in the included
> >script? Are they local to the function that calls include with the file name?
> >Thanks in advance;
> >I'm not sure where to look for this answer;
> >JK
> 
> 
> JK:
> 
> Whenever I have a question about an include, I just cut/paste (i.e., 
> replace) the include statement with the include script. That way I 
> know exactly what it does.

Sounds like a maintenance nightmare :|

To answer his question though, variables not declared via the "global"
keyword and not accessed via the super global variables ($GLOBALS,
$_SESSION, etc) inherit the scope in which the include statement occurs.
Therefore, if in the included file all you have is:

    $foo = 'foo';

Then it's scope is the function including the file.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to