include() will only load the file if the include() statement is encountered
during the execution of your script
        if (1==0) {
                include("file");
        }
the file will never be include()'d, since the if/then will always fail.

require() will always put the contents of the file being requie()'d
into your script, regardless if it is executed or not...
        if (1==0) {
                require("file");
        }
the contents of "file" will be placed inside of the if/then,
even though it'll never be executed.

also, include() is evaluated every time it is encountered,
whereas require() is only evaluated once...

**
**From the PHP.net website documentation**

The include() statement includes and evaluates the specified file.

If "URL fopen wrappers" are enabled in PHP (which they are in the default
configuration), you can specify the file to be include()ed using an URL instead of a
local pathname. See Remote files and fopen() for more information.

An important note about how this works is that when a file is include()ed or
require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the
target file, and resumes again at the end. For this reason, any code inside the
target file which should be executed as PHP code must be enclosed within valid PHP
start and end tags.

This happens each time the include() statement is encountered, so you can use an
include() statement within a looping structure to include a number of different
files.

include() differs from require() in that the include statement is re-evaluated each
time it is encountered (and only when it is being executed), whereas the require()
statement is replaced by the required file when it is first encountered, whether the
contents of the file will be evaluated or not (for example, if it is inside an if
statement whose condition evaluated to false).



> -----Original Message-----
> From: John Monfort [mailto:[EMAIL PROTECTED]]
> Subject: Re: [PHP] what's the difference between include and require??
>
>   An unsuccessful include will give you an error.
>
>   An unsuccessful require will kill the program.
>
> On Mon, 19 Feb 2001, Zenith wrote:
>
> > Though I have read the manual about these two things, include() and
> > require(), but I still not very clear about the difference between these??


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to