include(“./file.php”)和include(“file.php”)区别
浏览:11757次 出处信息
多数情况下,两种方式的区别可能在性能上有细微的区别(via)。 但是,在多重包含的情况下表现未必一样:
|-- index.php `-- lib |-- a.php `-- b.php
假定有三个文件,入口文件index.php,包含lib/a.php。a.php又需要包含它同目录下的b.php:
我们通过strace来跟踪一下方式2的系统调用(我的环境下include_path=.:/tmp):
open("/home/robin/devel/lib/a.php", O_RDONLY) = 3 open("/home/robin/devel/b.php", O_RDONLY) = -1 ENOENT (No such file or directory) open("/tmp/b.php", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/robin/devel/lib/b.php", O_RDONLY) = 3
官方文档的阐述是这样的:
Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include() will finally check in the calling script’s own directory and the current working directory before failing.
所以优先级应该是这样:
当然,比较推荐结合魔术常量__FILE__来include。
参考及延伸阅读:
建议继续学习:
- php两种include加载文件方式效率比较 (阅读:2740)
- require(),include(),require_once()和include_once()的异同 (阅读:2479)
- 再谈php的include和include_once(include和require_once) (阅读:2367)
- 从php核心代码看require和include的区别 (阅读:2089)
- 深入理解PHP之require/include顺序 (阅读:1931)
- 如何安全的Include文件 (阅读:1504)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:PHP的版本发布历程
后一篇:php的strtotime在处理am/pm时的一个BUG >>
文章信息
- 作者:肖斌 来源: 将之典藏
- 标签: include
- 发布时间:2011-09-19 23:24:32
建议继续学习
近3天十大热文
- [257] WEB系统需要关注的一些点
- [13] 哪本书是对程序员最有影响、每个程序员都该阅读
- [12] 深入剖析 redis replication
- [12] Python程序的执行原理
- [12] InnoDB insert性能拐点测试
- [12] 一次神奇的MySQL优化
- [11] Android设计中的.9.png
- [11] 我的git笔记
- [10] Spark性能优化——和shuffle搏斗
- [10] 修改系统最大文件句柄数