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"?
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.
"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.
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))?
I think require and include are used to handle error resulting from unavailable file
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!