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