Connecting Tech Pros Worldwide Forums | Help | Site Map

When should I use REQUIRE and when should I use INCLUDE?

erin g
Guest
 
Posts: n/a
#1: Jul 17 '05
What is the difference between REQUIRE and INCLUDE and in what
circumstances should one be used over the other?


Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: When should I use REQUIRE and when should I use INCLUDE?


On 25 Mar 2005 10:50:54 -0800, "erin g" <eringeyer@gmail.com> wrote:
[color=blue]
>What is the difference between REQUIRE and INCLUDE and in what
>circumstances should one be used over the other?[/color]

http://uk2.php.net/require
http://uk2.php.net/include/

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
frizzle
Guest
 
Posts: n/a
#3: Jul 17 '05

re: When should I use REQUIRE and when should I use INCLUDE?


'require' will stop processing if the file can't be included,
'include' will go on...

erin g
Guest
 
Posts: n/a
#4: Jul 17 '05

re: When should I use REQUIRE and when should I use INCLUDE?


thanks

Chung Leong
Guest
 
Posts: n/a
#5: Jul 17 '05

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.


Closed Thread