If I place an include or require statement inside a conditional that evaluates to false, will the PHP interpreter skip the include file altogether, or will it load it just in case?
An example would be:
if ($some_user_var) {
require 'this.php';
} else {
//do stuff
}
I read somewhere that require will always be included by the interpreter regardless of the conditional, but include will not. If that’s the case, just switching from require to include could mean a free speedup due to the reduced I/O and parsing overhead.
It probably makes a difference if I’m running a preprocessor like eAccelerator, but let’s assume I don’t.
It will only be included if the condition is true. I don’t know where you read otherwise, but they’re wrong.
The only difference between
includeandrequireis thatincludewill throw a warning if it fails, whereasrequirewill throw a fatal error.To confirm this, see the PHP manual page for
require.(ps – if you’re doing conditional includes, depending on what the reaon is, you may consider using
include_once()orrequire_once()instead)