Similarities and differences between include (), include_once (), require (), and require_once ()-unique196

Source: Internet
Author: User
Similarities and differences between include (), include_once (), require (), and require_once ()-unique196:

First, include (), include_once (), require (), and require_once () are used to include and run specified files, and the contained files are exactly the same in structure during execution.

Example: include ("file. php ");

Include_once ("file. php ");

Require ("file. php ");

Require_once ("file. php ");

Differences:

1. different use methods

Include () and include_once () are generally placed in the PHP process control program.

Require () and require_once () are usually placed at the beginning of the PHP program. before the PHP program is executed, it will first read the file specified by require.

2. errors are reported in different ways during execution.

When the include () or include_once () file does not exist or an error occurs, it continues to run and displays a warning error. a returned value is returned.

When require () or require_once () does not exist or an error occurs, the execution is stopped and an error is reported. a fatal error is displayed and no return value is returned.

The differences between include (), require (), include_once (), and require_once:

Include () and require (): When the same file is contained multiple times, the same file content is repeatedly imported.

Include_once (), require_once (): checks whether the target file has been imported before. If yes, the same file will not be imported repeatedly.

Now I have summarized so much and learned together!

Related Article

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.