PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<includeinclude_once>
Last updated: Mon, 16 Jul 2012

require_once()

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

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

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

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

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

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

<?php
require_once("a.php"); // this will include a.php
require_once("A.php"); // this will include a.php again on Windows!
?>

警告

Windows 版本的 PHP 在 4.3.0 版之前不支持本函数的远程文件访问,即使 allow_url_fopen 选项已被激活。

参见 require()include()include_once()get_required_files()get_included_files()readfile()virtual()




<includeinclude_once>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST