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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use