What is the purpose of using include in PHP, because if the file does not exist then there is something wrong with either the script or the web servers configuration. Surely it is better to use require so that the problem gets highlighted.
So, what is the purpose of include in the language?
For something that is not required for the page to run successfully.
For example, think about a web page. You have a sidebar containing ads that is shared between pages. As a good developer, you stay DRY and put this in an include file. You wouldn’t want the web page to fail (with fatal error) simply because the script couldn’t find the file (say your co-worker uploaded it to the wrong spot). As such, you use
includeinstead ofrequire.There are additional benefits – such as performance – to using
include. But that’s a real world example which should give you some perspective.