search
Homephp教程php手册php中的require_once()与include_once()

php中的require_once()与include_once()

Jun 14, 2016 am 12:02 AM
includephprequirecodeOpen sourceprogrammingprogramming languagesoftware development

php中的require_once()与include_once() phpma.com

require_once()include_once()phpma.com

require_once()语句在脚本执行期间包括并运行指定文件。此行为和 require() 语句类似,唯一区别是如果该文件中的代码已经被包括了,则不会再次包括。有关此语句怎样工作参见 require() 的文档。

require_once() 应该用于在脚本执行期间同一个文件有可能被包括超过一次的情况下,你想确保它只被包括一次以避免函数重定义,变量重新赋值等问题。 phpma.com

使用 require_once()include_once()的例子见最新的 PHP 源程序发行包中的 PEAR 代码。

 

注: require_once() 是 PHP 4.0.1pl2 中新加入的。 phpma.com

 

 

注: 要注意 require_once()include_once()在大小写不敏感的操作系统中(例如 Windows)的行为可能不是你所期望的。

例子 16-8. require_once()在 Windows 下不区分大小写

<span class="#000000"><font face="新宋体"><span class="#0000CC"><?php <br> </span><span class="#006600">require_once(</span><span class="#CC0000">"a.php"</span><span class="#006600">); </span></font><font face="新宋体"><span class="#FF9900">// this will include a.php<br> </span><span class="#006600">require_once(</span><span class="#CC0000">"A.php"</span><span class="#006600">); </span></font><font face="新宋体"><span class="#FF9900">// this will include a.php again on Windows!<br> </span><span class="#0000CC">?></span> </font></span>

The include_once()语句在脚本执行期间包括并运行指定文件。此行为和 include()语句类似,唯一区别是如果该文件中的代码已经被包括了,则不会再次包括。如同此语句名字暗示的那样,只会包括一次。

include_once() 应该用于在脚本执行期间同一个文件有可能被包括超过一次的情况下,你想确保它只被包括一次以避免函数重定义,变量重新赋值等问题。

使用 require_once()include_once() 的更多例子见最新的 PHP 源程序发行包中的 PEAR代码。

 

注: include_once() 是 PHP 4.0.1pl2 中新加入的。 phpma.com

 

 

注: 要注意 include_once()require_once() 在大小写不敏感的操作系统中(例如 Windows)的行为可能不是你所期望的。

例子 16-9. include_once()在 Windows 下不区分大小写

<span class="#000000"><font face="新宋体"><span class="#0000CC"><?php <br> </span><span class="#006600">include_once(</span><span class="#CC0000">"a.php"</span><span class="#006600">); </span></font><font face="新宋体"><span class="#FF9900">// this will include a.php<br> </span><span class="#006600">include_once(</span><span class="#CC0000">"A.php"</span><span class="#006600">); </span></font><font face="新宋体"><span class="#FF9900">// this will include a.php again on Windows!<br> </span><span class="#0000CC">?></span> </font></span>
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

MantisBT

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.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools