+ 2

include and require difference

Hello! I dont understand why somebody using require, some include if all files always available on hosting? Why not use always require? Also when we need Require/include ONCE if we can always use without "once"?

16th May 2020, 9:16 AM
Antony S
Antony S - avatar
5 Respuestas
0
There are many cases where you can link to a file which could be unavailable sometimes, for example if the file is pulling some data from a remote database and the server hosting the database sometimes happens to be down, you can use "include" so that when the file is not available it doesn't crash your whole application but rather generate a warning/error to the user (tell them to come back later or some other message) and then continue normal execution.
27th May 2020, 7:30 AM
ꪑꪖ᥊𝓲ꪑꫀ
ꪑꪖ᥊𝓲ꪑꫀ - avatar
0
"require" stops script execution and generates an error if the referenced file is not found while "include" doesn't stop script execution but generates a warning message. Oftentimes you may use require if the file must be available always otherwise do something else (using exceptions) while other times you may need to use include if it is not necessary for the file to be available all the time.
16th May 2020, 12:23 PM
ꪑꪖ᥊𝓲ꪑꫀ
ꪑꪖ᥊𝓲ꪑꫀ - avatar
0
Thanks i understand this, but i dont understand how file could be not available on hosting disk or why it can be not necessary if its describes important functions. For me if file not necessary - why i should ever link to it))?
18th May 2020, 4:15 PM
Antony S
Antony S - avatar
0
I think require and include are used to handle error resulting from unavailable file
28th Jul 2020, 6:30 PM
Israel Gabriel
Israel Gabriel - avatar
0
Hi ! We often use this tactic to make the most of time and avoid repeating certain parts of the program . In this way , we specify the part that is repeated in most of the sites that we create . Now we coding the same part and save it in a separate and smaller file. So every time we create a new site , if it needs this file , we recall it with this tactic. That way , we no longer need to rewrite that part. Write once use as much as you want!
26th Mar 2022, 5:40 PM
Mossi Pier
Mossi Pier - avatar