FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » require/include a file inside a function
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: require/include a file inside a function [message #172686 is a reply to message #172685] Thu, 24 February 2011 20:02 Go to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 2/24/2011 2:02 PM, Jerry Stuckle wrote:
> On 2/24/2011 11:54 AM, Twayne wrote:
>> In news:ik4la0$a4l$3(at)news(dot)eternal-september(dot)org,
>> Jerry Stuckle<jstucklex(at)attglobal(dot)net> typed:
>> :: On 2/23/2011 9:01 PM, Twayne wrote:
>> ::: In news:8s78bbFd6qU1(at)mid(dot)individual(dot)net,
>> ::: Simon<bad(at)example(dot)com> typed:
>> ::::: Hi,
>> :::::
>> ::::: is it possible to globally include(...) a file inside a
>> ::::: function?
>> :::::
>> ::::: What I am trying to do is prevent loading files until
>> ::::: they are really needed
>> :::::
>> ::::: currently I have something like...
>> :::::
>> ::::: // -----------------------
>> ::::: include 'large_a.php';
>> ::::: include 'large_b.php';
>> ::::: include 'large_c.php';
>> ::::: include 'large_d.php';
>> :::::
>> ::::: // -----------------------
>> :::::
>> ::::: but this is not ideal because I might never need those
>> ::::: files...
>> ::::: I would much rather have something like
>> :::::
>> ::::: // -----------------------
>> ::::: function load_large_class( $a )
>> ::::: {
>> ::::: if( $a == $condition_a )
>> ::::: include 'large_a.php';
>> ::::: if( $a == $condition_b )
>> ::::: include 'large_b.php';
>> ::::: if( $a == $condition_c )
>> ::::: include 'large_c.php';
>> ::::: if( $a == $condition_d )
>> ::::: include 'large_d.php';
>> ::::: }
>> ::::: // -----------------------
>> :::::
>> ::::: but as you know that will only locally include the file,
>> ::::: all classes, variables etc will only 'exist' for the
>> ::::: life of the function.
>> :::::
>> ::::: Would there be an easy way around this problem?
>> :::::
>> ::::: I guess I could always have a small file that says
>> :::::
>> ::::: // -----------------------
>> ::::: if( $a == $condition_a )
>> ::::: include 'large_a.php';
>> ::::: if( $a == $condition_b )
>> ::::: include 'large_b.php';
>> ::::: if( $a == $condition_c )
>> ::::: include 'large_c.php';
>> ::::: if( $a == $condition_d )
>> ::::: include 'large_d.php';
>> ::::: // -----------------------
>> :::::
>> ::::: but for the purpose of what I am trying to do I would
>> ::::: prefer a function
>> ::::: as it would be neater to maintain/use.
>> :::::
>> ::::: Many thanks in advance
>> :::::
>> ::::: Simon
>> :::
>> ::: Yes.
>> :::
>> :::
>> ::
>> :: No.
>> ::
>> ::
>> Stuck, maybe you can't, but I certainly can here and use such a
>> mechanism on
>> two sites that are functioning perfectly. There will be gotchas in ANY
>> methodology but this one works well. Try it; you'll see.
>> I'll not make a troll fest out of this, so flail away if you wish; we've
>> all seen you at work by now.
>>
>> HTH,
>>
>> Twayne`
>>
>>
>
> OK, troll, you're resorting to personal attacks again - but that's
> exactly like you.
>
> The fact is - anything included from within a function is local to that
> function only.

Wwwwweeeeellllllllllll, that's not strictly true. If you have globals
turned on, and define something as global, then won't it be visible
outside the function? If you define a session variable (super-global)
inside a function, doesn't it retain its value outside the function?

OK, I know that is not what you meant, but your statement is not exactly
100% accurate as written when read by and independent reader.

--
Shelly
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Proxy to open blocked sites
Next Topic: problem with web service
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 11:47:18 GMT 2024

Total time taken to generate the page: 0.03807 seconds