简体   繁体   English

包含路径的PHP 5.3和5.6之间的区别

[英]difference between php 5.3 and 5.6 with include path

We are upgrading our system from PHP 5.3 to 5.6 on an Apache 2.4.18 server running on Windows 7, we ran into a problem with include files. 我们正在Windows 7上运行的Apache 2.4.18服务器上将系统从PHP 5.3升级到5.6,我们遇到了包含文件的问题。

We were using full path for our includes ie 我们正在使用完整路径进行包含,即

include("c:\webSpace\Library\employee.php");

This runs just fine in 5.3. 这在5.3中运行得很好。 But in newer versions 5.6 and 7, file names that started with and "e" were escaped so the executed code looked like this 但是在较新的版本5.6和7中,以和开头的文件名被转义,因此执行的代码如下所示

include("c:\webSpace\Librarymployee.php");

We came up with two solutions: 我们提出了两种解决方案:

1.escape the \\ like so: 1.像这样转义\\

include("c:\webSpace\Library\\employee.php");
  1. add the include path to the php.ini file like so: 将包含路径添加到php.ini文件中,如下所示:

    include_path = ".;C:\\webSpace\\Library" include_path =“。; C:\\ webSpace \\ Library”

and then the include would look like this: 然后包含将如下所示:

include("employee.php");

My questions are these: 我的问题是:

1.What happened between version 5.3 and 5.6 that caused this problem 1,版本5.3和5.6之间发生了什么导致此问题

2.Why do files not starting with "e" execute just fine like this: 2.为什么不以“ e”开头的文件执行如下:

include("c:\webSpace\Library\payScale.php");

What you're seeing is a result of the escape sequence \\e , which is the ESC character (0x1B (27) in ASCII). 您所看到的是转义序列\\e ,它是ESC字符(ASCII中的0x1B(27))。 This was added in PHP 5.4.4, which explains the difference between versions. 这是在PHP 5.4.4中添加的,它解释了版本之间的差异。 This only occurs with that exact character sequence ("\\e"), which explains why the other paths work fine. 这仅在该确切的字符序列(“ \\ e”)发生时发生,这解释了为什么其他路径可以正常工作。

Also, this only occurs within double-quoted strings, so another solution is to simply use single quotes around your paths. 另外,这仅在双引号字符串内发生,因此另一种解决方案是在路径周围仅使用单引号。

Just to be clear, you would have similar issues if your paths used any of the escape sequences, such as \\n (linefeed) or \\t (tab). 请注意,如果路径使用任何转义序列,例如\\n (换行)或\\t (制表符),您也会遇到类似的问题。 See the link below for a full list. 请参阅下面的链接以获取完整列表。 It's just a consequence of using Windows-style backslash directory separators inside double-quoted strings. 这只是在双引号字符串内使用Windows风格的反斜杠目录分隔符的结果。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM