php5.4+和 php7.0 的包含路径问题 实在找不到原因啊啊啊啊啊啊

2016-12-29 13:12:24 +08:00
 iscraft
网站根目录 index.php 中

include "/test.php";
在 5.4 以及 5.6 下正常执行
在 7.0 下则 failed to open stream: No such file or directory

include "test.php";
在 3 个版本下都正常没问题

从早上 google 到现在都没找到 php7 的哪部分新特性和遗弃功能里有讲这个的 求教!
4112 次点击
所在节点    PHP
27 条回复
iscraft
2016-12-29 15:45:35 +08:00
@Felldeadbird 写法是不对 但在 windows 的同一个 apache2.4.7 下分别加载了 5.2/5.4/5.6/7.0.12 针对 /符号 7 出现了错误 就想搞明白这个是为啥
greatonce
2016-12-29 15:50:37 +08:00
@iscraft

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. The include construct will emit a warning if it cannot find a file; this is different behavior from require, which will emit a fatal error.

http://php.net/manual/zh/ini.core.php#ini.include-path
greatonce
2016-12-29 15:52:27 +08:00
@iscraft 因为你的 include_path 配置 指定了当前目录可以被当做搜索目录, php7 的配置可能没有这个而已

你可以看看 几个不同版本的 php.ini 里面的 include_path 选项。
iscraft
2016-12-29 16:07:45 +08:00
@greatonce php.ini 中 include_path 选项均未打开
greatonce
2016-12-29 17:34:36 +08:00
@iscraft 你在二楼不是回复了吗,没打开不可能有你在二楼说的那个设置,你看的可能是 php.ini 的模板,而不是真正的配置文件。

总之,这种写法肯定不对,网站 url 和系统路径不是一回事。
lslqtz
2016-12-29 17:38:42 +08:00
使用相对路径不好吗?
royantar
2016-12-29 17:51:09 +08:00
7.0 版本将 Windows 环境下这样的路径视为绝对路径:

#if PHP_WIN32
/* This should count as an absolute local path as well, however
IS_ABSOLUTE_PATH doesn't care about this path form till now. It
might be a big thing to extend, thus just a local handling for
now. */
filename_length >=2 && IS_SLASH(filename[0]) && !IS_SLASH(filename[1]) ||
#endif

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/330982

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX