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

Home » Imported messages » comp.lang.php » Is there any situation where anything other than require_once is better?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Is there any situation where anything other than require_once is better? [message #171933 is a reply to message #171923] Fri, 21 January 2011 20:59 Go to previous messageGo to previous message
Jo Schulze is currently offline  Jo Schulze
Messages: 15
Registered: January 2011
Karma:
Junior Member
Leonardo Azpurua wrote:

> I have so far used "include" (coming from "C", I just saw it and
> understood it).
>
> Then I read about "require" and "require_once."

For someone coming from C:

You'll have to understand that PHP include/require isn't a preprocessor
thing and PHP is an interpreted language, unlike C.

The difference between PHP include* vs. require* is that require will
cause a fatal error (stopping execution), include will only issue a
warning.

The *once behavior is a shortcut for the C sheme to make sure that a
file will only included once. Wherever the C equivalent would be

#ifdef INCLUDED_FOO

[whatever]
#define INCLUDED_FOO 1
#endif

you're choice in the PHP world would be *_once

As stated in this thread, there is a need to require/include Scripts in
PHP without the once thing because it's an interpreted language which
may produce different output when inluded in different status.

In practice, I use the require* and see rare use of the BC include
constructs.

HTH
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Syntax for trim charlist?
Next Topic: SNMPv3 for PHP?
Goto Forum:
  

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

Current Time: Sat Nov 23 04:57:38 GMT 2024

Total time taken to generate the page: 0.04573 seconds