search
Homephp教程php手册require()和include()的区别-摘自网猴

include|区别

在PHP中使用头文件,会涉及两个函数:include()和require()。这两个函数差别很小,却很重要,所以我们要认真研究一下。require()函数工作方式与XSSI相类似;不管在程序的哪个部分使用了这个函数,只有程序一开始运行,头文件的内容就被作为程序本身的一部分来处理。因此,如果您在一个条件判定语句中使用了require()函数,那么即使这个条件即使不为真,头文件也会被包含进来。

而include()函数只是在执行到这一条语句时才会把头文件内容包含进来。如果程序没运行到这里,那PHP是不会管它的。这就意味着,您在条件判定部分使用include时,它会完全按照您希望的那样工作。

还有,如果您用了require()函数,而您指定的头文件并不存在,那么程序将会停止运行并产生错误。如果您用了include(),程序会产生一个警告信息,但是会继续运行。



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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software