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 #171994 is a reply to message #171933] Wed, 26 January 2011 10:51 Go to previous message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma:
Member
Jo Schulze <antispam(at)feuersee(dot)de> wrote:

> 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:

<snip>

> 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

<OT>

As far as I can tell, this won't accomplish anything unless you
explicitly #define "INCLUDED_FOO" before the #include, which seems
an unnecessary hassle. On top of that, the "#define INCLUDED_FOO
1" would then be useless.

In C, implementing idempotent #include's generally looks more like:

#ifndef FOOBAR_H_
#define FOOBAR_H_

/* preprocessor stuff */

#endif

</OT>

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

Interestingly, I came across Rasmus Lerdorf's* thoughts on the
matter:

| Try to avoid using include_once and require_once if
| possible. You are much better off using a straight
| include or require call, because the *_once() calls are
| very slow under an opcode cache. Sometimes there is no
| way around using these calls, but recognize that each
| one costs you an extra open() syscall and hash look up.

Source: <http://toys.lerdorf.com/archives/38-The-no-framework-PHP-
MVC-framework.html>

That post was last modified about a year ago, so I'm unsure if the
implementations of include's and require's were changed since then.


* Original implementer of PHP.

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
[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 00:58:05 GMT 2024

Total time taken to generate the page: 0.04366 seconds