Forum Moderators: coopster

Message Too Old, No Replies

When to use include_once() vs. just include()

         

neophyte

6:23 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Is the appropriate use of include_once() and require_once() just when you need to include a file within a loop, or if your calling the same page sequentially (like a form action which uses $_SERVER['PHP_SELF')?

If you're not recalling a page sequentially - or running a loop - I guess just include() or require() would suffice.

Is this true, or am I off base here?

Neophyte

jatar_k

6:40 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the _once variants will help in case you have a lot of includes in a lot of files. Anytime anything tries to get included twice it will stop it from being reparsed.

I use them when I am working with other programmers, when I work alone I seldom use them.

<added>thought of something else

I include content
I require libs once

coopster

6:45 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>...when I work alone I seldom use them

C'mon, I know the real reason why you don't, it's because they [pear.php.net] say you should ;)

jatar_k

6:46 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



another good point ;)