What’s the different between include and require?

shophia

Member
Registered
Joined
Mar 25, 2013
Messages
23
Points
0
Both are PHP syntax and used for including the files in the php files, however the difference is,

If the file is not found by require() syntax, it will reason a fatal error and end the execution of the script.
If the file is not found by include() syntax, a warning will be mattered, however execution will never end .
 

Marc0

Well-known member
Registered
Joined
Jun 6, 2012
Messages
890
Points
28
Basically, the two functions are implemented include and require the same: PHP will load the entire contents of the file include or require, no matter what the format. For content in php tags will be executed as normal php file. For content outside of php tags will be printed.

Different between include and require in PHP:
include("file.php"): if the file does not exist file.php it will automatically execute the script again.

require ("file.php"): if the file does not exist, it will stand always file.php and execute any script that does the following. Therefore require the file is the most important file.

include_one like include, however include_once include only one single time.

require_once requires only 1 time for loading and it will not call for next loadings.
 

semaphore.v

Member
Registered
Joined
Jun 26, 2013
Messages
62
Points
0
The include() and require() are almost similar except the way they handle failures. include() produces a warning and require() produces a fatal error.
 

seoguy

New member
Registered
Joined
Aug 6, 2013
Messages
11
Points
0
Unlike include(), require() will always read in the target file, even if the line it's on never executes. If you want to conditionally include a file, use include(). The conditional statement won't affect the require(). However, if the line on which the require() occurs is not executed, neither will any of the code in the target file be executed.
 

gracerivas

New member
Registered
Joined
Aug 20, 2013
Messages
4
Points
0
include returns a warning incase the included file does not exist or contains an error. while require returns fatal error included file does not exist or contains an error
 

furious

New member
Registered
Joined
Nov 10, 2013
Messages
11
Points
0
oh php sounds so difficult but once you understand it is a very easy and strong language to start with
 
Older Threads
Replies
1
Views
2,261
Replies
13
Views
8,919
Replies
23
Views
8,201
Replies
0
Views
2,018
Replies
9
Views
4,716
Newer Threads
Replies
4
Views
2,380
Replies
2
Views
2,634
Replies
0
Views
4,550
Replies
3
Views
2,206
Replies
0
Views
2,183

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top