Re: require/include a file inside a function [message #172503 is a reply to message #172484] |
Mon, 21 February 2011 13:07 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 2/21/2011 12:39 AM, Simon wrote:
>>
>> If you try it you will find that included code is included at the
>> point where the include is written. So if that it in a function, that
>> will be where the code is.
>
> Not sure I follow,
>
> If I have something like
>
> function fn_b()
> {
> include (a_big_file.php);
> }
>
> function fn_a()
> {
> fn_b();
>
> // stuff, (functions, classes), created in fn_b() are not available
> // to me here anymore.
> // I am using 5.2.14 (dev) and 5.3.2 (live), (don't even ask me why!).
> }
>
>>
>> Take a look at the php magic function autoload:
>> http://www.phpro.org/tutorials/SPL-Autoload.html
>
> Yes, this looks like it might actually help.
>
> I will try, (I only got to work now), and see if files included in a
> function that create a class still make the class globally available.
>
> Simon
>
No, files included in a function are NEVER accessible globally. They
are only available in the function - it's part of what functions do.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|