About the difference between Require,require_once,include and include_once, requireonceinclude_php tutorial

Source: Internet
Author: User

About the difference between Require,require_once,include and include_once, Requireonceinclude


First, the definition

Require,require_once,include,include_once are all PHP keywords, which means that they are actually PHP statements, not functions, like Print,echo, but also the output statements of PHP, not functions. But more often than not, people are called functions.

Second, usage

Require ' test.php ', require_once ' test.php ', or require (' test.php '), require_once (' test.php ') are all possible, as is the case for include. They are used when you need to introduce another file in one file. Although they can be parentheses, but not functions, I prefer to use quotation marks.

Iii. the difference between require and require_once

When require () is referenced in the current file, multiple references or duplicates of the class or method may occur. When require_once () receives an address as a parameter and is referenced in the current file, it first checks whether the class or method in the referenced file has been referenced or has occurred, ensuring that the class or method is not referenced.

Iv. the difference between include and include_once

Include has the same effect as require,include_once and require_once.

Five, the difference between include (include_once) and require (require_once)

Include and include_once when referencing a file, if an error occurs, a warning is issued, and the referenced file is stopped running, and then the current file continues to run, and the overall code runs without stopping.

Require and require_once when referencing a file, if an error occurs, a warning is issued immediately and then the overall code is stopped. So require and require_once want to be safer.

Vi. Advantages and Disadvantages

Require_once need to run longer, so the efficiency is relatively low. Require is a better choice if time takes precedence, but time and efficiency are a balance in more times.

Seven, use

Require and require_once are generally used to include class files. Include and include_once are typically used to include template files.

(There are not exact places, please point out)

http://www.bkjia.com/PHPjc/1051220.html www.bkjia.com true http://www.bkjia.com/PHPjc/1051220.html techarticle on the difference between Require,require_once,include and include_once, Requireonceinclude one, define Require,require_once,include,include_ Once are the keywords of PHP, which means they are real ...

  • 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.