top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the differences between require and include in PHP?

+2 votes
773 views
What are the differences between require and include in PHP?
posted May 29, 2014 by Karamjeet Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+1 vote

The key difference between require() and include() is that if you require() a file that can't be loaded (e.g. if it isn't there) then it generates a fatal error which will halt the execution of the page completely, and no more output will be generated. On the other hand, if you include() a file that can't be loaded, then this will merely generate a warning and continue building the page.

require will produce a fatal error (E_COMPILE_ERROR) and stop the script
include will only produce a warning (E_WARNING) and the script will continue

answer May 29, 2014 by Vrije Mani Upadhyay
0 votes

You may like to know Include_once also -

include - will include the specified file.
include_once - will include the file only once even if the code of the file has been included before.

Now coming to your query -
The include and require are almost similar except the way they handle failures. include produces a warning and require produces a fatal error i.e. does not allow the processing of the page.

answer May 30, 2014 by Salil Agrawal
0 votes

Both require and include are used to include a file but they differ in the way, they handle the failures.
require sends a fatal error and stops the page execution.whereas include gives a warning and continues building the page.

answer May 30, 2014 by Mohit Sharma
Similar Questions
0 votes

I use the pretty large Library PHP Image Workshop (http://phpimageworkshop.com/) at my project. It is about 75,5 KB. Everything works fine but if I try to include a 15 KB file with country codes, it fails. With the other files I easily get over 100 KB inclusion size, so my question; Is there a size limitation for include?

...