文件的包含:
Include / include_once
Require /require_once
Include 和require都是把一个页面引入到当前页面.
怎么来理解"引入".
就相当于把被包含文件的所有代码,替换include/require那一句.
和直接把代码写在include那一句是一样的.
Require作用也是把一个文件引入到当前文件.
理解与include一样.
Include与require的区别
答:include如果引入的文件不存在,试图继续往下执行,报一个warning
(如果你不介意之前的内容是否被包含,之后的内容都要执行,就使用include)
而require如果引入的文件不存在,报fatal error,不再继续执行.
(如果之前的内容一定要被包含,才允许继续执行之后的代码,就使用require)
========================================================
Include/require 与 include_once /require_once的区别
_once 会自动判断文件是否已经引入,如果引入,不再重复执行.
即:保证被包含文件只可能被引入一次.
(如果包含的文件里有定义函数,那么被包含的文件只能被包含一次,如果多次包含,就会出现函数重定义的错误,php是不运行函数重定义的,会出现致命错误,之后代码不在运行)
=======================================================
有的文件不允许被包含多次?
可以用_once来控制,
但是,如果从文件的设计上,比较规范,能保证肯定不会出现多次包含的错误,
这种情况下 建议用include
因为include_once要检测之前有没有包含,效率没有include高
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use
