| re: When should I use REQUIRE and when should I use INCLUDE?
"erin g" <eringeyer@gmail.com> wrote in message
news:1111776654.744830.88810@g14g2000cwa.googlegro ups.com...[color=blue]
> What is the difference between REQUIRE and INCLUDE and in what
> circumstances should one be used over the other?
>[/color]
Not much of a difference really. The fact that we have both is entirely
historical. In PHP 3, require's are evaluated as the file is parsed. Code in
a require'ed file is linked into the running script even if it's never
executed. The following, for example, would throw an fatal error:
if(file_exists("idontexists.php3")) {
require("idontexists.php3");
}
Include's on the other hand occur at runtime, so the above fragment, with
include in place of require, would work as intended.
Starting with PHP 4, require's occur at runtime too. The only difference
remaining between the two is the type of error emitted as others have
already explained.
I personally use require almost exclusively. |