include("somefile.php");include_once("somefile.php");require("somefile.php");require_once("somefile.php");
What is the difference between these?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The difference between
include()andrequire()is that theinclude()construct will emit a warning if it cannot find a file; this is different behavior fromrequire(), which will emit a fatal error (and stop the execution of the script).include_once()andrequire_once()has the exact same behavior thaninclude()andrequire(), except PHP will check if the file has already been included, and if so, not include (require) it again.include_once()andrequire_once()is especially useful in cases where you are including files containing class and/or function definitions. It prevents you from accidentally including the same file twice and causing “double definition” errors.