RE: [PHP] what's the difference between include and require??
| From: | Sam Leibowitz | Date: | Tue, 20 Feb 2001 16:18:54 +0000 |
| Subject: | RE: [PHP] what's the difference between include and require?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-40755@lists.php.net to get a copy of this message | ||
> An unsuccessful include will give you an error.
>
> An unsuccessful require will kill the program.
Also: require() statements cannot be embedded inside conditionals. For
example:
<?PHP
if ($something) {
include("somefile.php") // this is okay.
}
if ($something) {
require("somefile.php") // this is wrong.
}
?>
The reason: require() is taken care of on an initial pass of the parser,
which makes it faster than include(). Unfortunately, that means that the
parser doesn't check to see if it's embedded in a conditional statement.
Finally, unless you're using these functions to pull in actual HTML, as
opposed to code, think hard about using include_once() or require_once(),
which spares you those obnoxious "Cannot redefine function blah() in blah
blah blah" errors.
-----
Sam Leibowitz (sleibowitz@btcwcu.org)
Project Manager
Business Technology Center