您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 南充分类信息网,免费分类信息发布

php如何实现include_once

2024/8/21 13:14:14发布21次查看
include_once 语句在脚本执行期间包含并运行指定文件。此行为和 include 语句类似,唯一区别是如果该文件中已经被包含过,则不会再次包含。如同此语句名字暗示的那样,只会包含一次。
include_once 可以用于在脚本执行期间同一个文件有可能被包含超过一次的情况下,想确保它只被包含一次以避免函数重定义,变量重新赋值等问题。
note:(推荐学习:php编程从入门到精通)
在 php 4中,_once 的行为在不区分大小写字母的操作系统(例如 windows)中有所不同,例如:
include_once 在 php 4 运行于不区分大小写的操作系统中
<?phpinclude_once "a.php"; // 这将包含 a.phpinclude_once "a.php"; // 这将再次包含 a.php!(仅 php 4)?>
此行为在 php 5 中改了,例如在 windows 中路径先被规格化,因此 c:\progra~1\a.php 和 c:\program files\a.php 的实现一样,文件只会被包含一次。
include和include_once:
include载入的文件不会判断是否重复,只要有include语句,就会载入一次(即使可能出现重复载入)。
而include_once载入文件时会有内部判断机制判断前面代码是否已经载入过。
这里需要注意的是include_once是根据前面有无引入相同路径的文件为判断的,而不是根据文件中的内容(即两个待引入的文件内容相同,使用include_once还是会引入两个)。
//test1.php<?phpinclude './test2.php';echo 'this is test1';include './test2.php';?>//test2.php<?phpecho 'this is test2';?>//结果:this is test2this is test1this is test2//test1.php<?phpinclude './test2.php';echo 'this is test1';include_once './test2.php';?>//test2.php<?phpecho 'this is test2';?>//结果:this is test2this is test1//test1.php<?phpinclude_once './test2.php';echo 'this is test1';include './test2.php';?>//test2.php<?phpecho 'this is test2';?>//结果:this is test2this is test1this is test2//test1.php<?phpinclude_once './test2.php';echo 'this is test1';include_once './test2.php';?>//test2.php<?phpecho 'this is test2';?>//结果:this is test2this is test1
以上就是php如何实现include_once的详细内容。
南充分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录