Page 1 of 1

diff between include and require_once()

Posted: Tue Aug 26, 2003 10:23 am
by ericsodt
anyone?? whats the difference between the two.??

Posted: Tue Aug 26, 2003 10:30 am
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().

Posted: Tue Aug 26, 2003 12:17 pm
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?

Posted: Tue Aug 26, 2003 12:36 pm
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

Posted: Tue Aug 26, 2003 8:37 pm
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.

Posted: Wed Aug 27, 2003 5:02 am
by volka
oops, I understood it this way. Of course it only effects the handling within one request