This article aims to serve for beginner PHP developers but those who are comfortable with PHP will also find this article useful. Basically, I’ll tell you the difference between some of PHP commonly used functions/features. By the end of this article you will have a clear difference among:
* include VS require
* include_once VS include
* require_once VS require
* echo VS print
* Single quote VS Double quote
Apparently all functions in each above point work in similar fashion. However, they are slightly different from other. Continue reading to explore the differences.
include VS require
Both are frequently used to include other files into our PHP code. Following are the differences between ‘include’ and ‘require’:
* ‘include’ throws a warning, if your specified file is not found. Rest of the code will be rendered.
* ‘require’ throws a fatal error, if your specified file is not found. Rest of the code will not be rendered.
include_once VS include AND require_once VS require
‘include_once’ and ‘require_once’ are same in nature. Here we will see the difference of ‘include_once’ against ‘include’. Following are the differences between ‘include’ and ‘include_once’:
* All includes for same file will be rendered, if you are using ‘include’.
* While all includes for same file will be rendered only once, if you are using ‘include_once’. This helps you to prevent an error, if same file included again.
Single quote VS Double quote
This might be very confusing for many developers to choose between single and double quote for writing string. There is a couple of difference between using single and double quote:
* Any variable or special character like \n \r etc under the single quote will not be rendered. It will be displayed as an string.
* Any variable or special character like \n \r etc under the double quote will be rendered properly.