require_once(), require(), include().What is difference between them?

Posted on

If the file is not found by require(), it will cause a fatal error and halt the execution of the script (script will not be continue/stops the execution). If the file is not found by include(), a warning will be issued, but execution will continue.

require() includes and evaluates a specific file, while require_once() checks whether this file included or not on the same page. So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don’t include the file more times and you will not get the “function re-declared” error.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s