diff between include and require_once()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

diff between include and require_once()

Post by ericsodt »

anyone?? whats the difference between the two.??
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

include_once() require_once() -
The diff is between error handling. If include_once() fails it generates Warning i.e program execution will continue, whereas if require_once() fails it generates Fatal error i.e program execution stops.

require_once() says the file is require, without it the program can't go ahead, unlike include_once().
NoReason
Forum Commoner
Posts: 51
Joined: Tue Sep 10, 2002 6:19 pm

Post by NoReason »

Oook... So what is the differance though.. between a; require_once, and a require.

the way I see it is, require_once will only include the document once and never parse it again, where as a require will (like include) be parsed each time teh page is loaded.. and ya the error handeling is differant.

is that correct?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://php.net/require_once wrote: The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again. See the documentation for require() for more information on how this statement works.
yes
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

the way I see it is, require_once will only include the document once and never parse it again, where as a require will (like include) be parsed each time teh page is loaded.. and ya the error handeling is differant.

is that correct?
Er.. no. volka had it right, but he forgot to correct you on that one. If you require() a file twice in the same page, it will be parsed twice. If you require_once() a page twice, it will be parsed the first time, and ignored the second time.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

oops, I understood it this way. Of course it only effects the handling within one request
Post Reply