PHP: Include vs. Require

Both are used to include external file to the script.

Include

When the file we are trying to include does not exist or the permission is incorrect, this will give you a warning and continue the script.

PHP

Require

When the file we are trying to include does not exist or the permission is incorrect, this will give you a warning, throw an Error, and terminate the script.

PHP

Error Handling

For warning suppresion we can set the runtime configuration with:

PHP

For error suppresion, we catch the exception with try-catch block:

PHP

References:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *