search
Homephp教程php手册include()、include_once()与require()、require_once()的异同点 - unique196

相同点:

首先include()、include_once()与require()、require_once()都是用来包含并运行指定文件的,并且包含的文件在执行时在结构上是完全一样的。

例如:include("file.php");

   include_once("file.php");

   require("file.php");

   require_once("file.php");

 

不同点:

1.使用方式不同

  include()、include_once()一般放在PHP流程控制程序中。

  require()、require_once()通常放在PHP程序的最前面,PHP程序执行前就会先读入require()所指定的文件。

2.执行时报错方式不同

  include()、include_once()在遇到包含文件不存在或出错时,则继续执行并显示警告错误,有返回值。

  require()、require_once()在遇到包含文件不存在或出错时,则停止执行并报错,显示致命错误,无返回值。

 

include()、require()与include_once()、require_once()的区别:

include()、require():当多次包含同一个文件时,就会重复导入多次相同的文件内容。

include_once()、require_once():会先检查目标文件是不是在之前就已经导入过了。如果是的话,就不在重复导入相同文件。

 

目前就总结了这么多,一起学习!

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function