The difference between PHP require (), include (), require_once (), and include_once ()

Source: Internet
Author: User

See online about require and include how to choose, pro-Test and summed up a bit:

1. The _once suffix indicates that loading is not repeated.

2. Error:

    • When the include introduces a file, if it encounters an error, it throws a hint and continues to run the code below (Warning);
    • Require when the file is introduced, if it encounters an error, it throws a hint and stops running the code below (Fatal error);

3. Practice:

Require-contains functions and variables. Usually placed at the beginning of the program, the PHP program before execution, will be read into the require designated by the introduction of the file to become a part of the Web page.
Include-is usually placed in the processing part of the process control to streamline the process. The PHP Program page reads the include file before it is read in.

4. the following rules apply before PHP 4.0.2:

require require require require require

5. Return value:

Although the include () and require () will return 1 after a successful reference, the $ret = include (' foobar.php ') will only make sense if require () is fatal if the reference fails.

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.