For the difference between require, require_once, include and include_once, requireonceinclude

Source: Internet
Author: User

For the difference between require, require_once, include and include_once, requireonceinclude

I. Definition

Require, require_once, include, and include_once all belong to PHP keywords. That is to say, they are actually PHP statements, rather than functions. Similar to print and echo, they are also PHP output statements, rather than functions. But in more cases, it is often called a function.

Ii. Usage

Require 'test. php ', require_once' test. php ', or require ('test. php '), require_once ('test. php. They are used to introduce another file in one file. Although they can contain parentheses, they are not functions. I prefer to use quotation marks.

Iii. Differences between require and require_once

When require () is referenced in the current file, multiple references or repetitions of classes or methods may occur. Require_once () receives an address as a parameter. When cited in the current file, it first checks whether the referenced or referenced class or method exists in the referenced file, make sure that the class or method has not been referenced.

Iv. Differences between include and include_once

Include works the same as require, include_once, and require_once.

5. Differences between include (include_once) and require (require_once)

When include and include_once reference a file, if an error occurs, a warning is issued, the Referenced File is stopped, and the current file continues to run. The overall code will not stop running.

When require and require_once reference a file, if an error occurs, a warning is immediately issued and the overall code is stopped. Therefore, require and require_once are more secure.

Vi. Advantages and Disadvantages

Require_once requires a longer running time, so the efficiency is relatively low. If time is preferred, require is a better choice, but in more cases, time and efficiency are a balance.

7. usefulness

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

(If there is any inaccuracy, please note)

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.