The difference between include and require

Source: Internet
Author: User

The difference between include and require 1, the way the load fails to handle different include and require in addition to the way in which files are introduced, the biggest difference is that include generates a warning when the file is introduced and the script will continue to execute. Require causes a fatal error and the script stops executing.
 If hello.php does not exist, echo ' world ' can continue.
 If hello.php does not exist, echo ' Hello ' will not be executed and will cease to require. 2, include () is a conditional include function, and require () is an unconditional include function. if (false) {include ' file.php ';//file.php will not be introduced} if (false) {require ' file.php ';//file.php will be introduced}3, file reference method include return value, and R Equire No $retval = include (' somefile.php '), if (!empty ($retVal)) {echo "file contains success";} else{echo "file contains failed";} Include () files that need to be referenced each time they are read and evaluated, require () will need to refer to the file to be processed only once (in fact, the file content to be referenced at the time of execution replaces the require () statement) It can be seen that if you have code that contains one of these directives and code that might execute multiple times, using require () is more efficient, and if you read different files each time you execute the code or have loops that pass through a set of file iterations, use include (), require usually use the method, This function is usually placed at the front of the PHP program, and before the PHP program executes, it is read into the file specified by require to make it a part of the PHP program's Web page. Commonly used functions, you can also use this method to introduce it into the Web page. Include typically uses methods, which are generally placed in the processing part of the process control. The PHP Program page reads the include file before it is read in. In this way, the process of executing the program can be simplified in addition to the question of whether or not parentheses are appended to the include and require, theoretically: there is no difference between include and require, but with parentheses being less efficient, So there is no parentheses in the back.

The above introduces the difference between include and require, including the contents of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.