include(“./file.php”)和include(“file.php”)区别
浏览:12581次 出处信息
多数情况下,两种方式的区别可能在性能上有细微的区别(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加载文件方式效率比较 (阅读:3388)
- require(),include(),require_once()和include_once()的异同 (阅读:3167)
- 再谈php的include和include_once(include和require_once) (阅读:3150)
- 从php核心代码看require和include的区别 (阅读:2829)
- 深入理解PHP之require/include顺序 (阅读:2590)
- 如何安全的Include文件 (阅读:2458)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:PHP的版本发布历程
后一篇:php的strtotime在处理am/pm时的一个BUG >>
文章信息
- 作者:肖斌 来源: 将之典藏
- 标签: include
- 发布时间:2011-09-19 23:24:32
建议继续学习
近3天十大热文
-
[1197] WordPress插件开发 -- 在插件使用 -
[88] 解决 nginx 反向代理网页首尾出现神秘字 -
[43] web开发设计人员不可不用的在线web工具和 -
[30] Rax 系列教程(长列表) -
[29] 一句话crontab实现防ssh暴力破解 -
[29] Java开发岗位面试题归类汇总 -
[29] 手机产品设计方向 -
[28] 如何建立合适的索引? -
[26] 程序员疫苗:代码注入 -
[25] 我对学习oracle与成长的理解
