Full path for include files (differences between 5.3 and 5.6)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Full path for include files (differences between 5.3 and 5.6)

    In upgrading our system from PHP v 5.3.3 to 5.6.x on a apache 2.4.18 server running on Windows 7, we ran into a problem with include files.

    We were using full path for our includes i.e.
    Code:
    include("c:\webSpace\Library\[B]e[/B]mployee.php")
    This ran just fine in v5.3.3 But in newer versions 5.6 and 7, file names that started with an "e" were escaped so it was transmitted like this:
    Code:
    include(c:\webSpace\Library[B]m[/B]ployee.php)
    Of course there were two solutions:

    1. escape the \ like so:
    Code:
    include("c:\webSpace\Library[B]\\e[/B]mployee.php")
    2. Or perhaps the better option add the path to php.ini file like so:
    Code:
    include_path = ".;C:\webSpace\Library"
    then the include would look like this:
    Code:
    include("employee.php")
    eliminated the path all together.


    My questions are these:
    1. What happened between version 5.3.x and 5.6.x?

    2. Why are only files starting with the letter "e" affected?
    A file like this still worked just fine -
    Code:
    include("c:\webSpace\Library\payScale.php")
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    I resolved my issue and thought it best not to leave this question hanging in case others are wondering the same.

    What you're seeing is a result of the escape sequence \e, which is the ESC character (0x1B (27) in ASCII). This was added in PHP 5.4.4, which explains the difference between versions. This only occurs with that exact character sequence ("\e"), which explains why the other paths work fine.

    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). It's just a consequence of using Windows-style backslash directory separators inside double-quoted strings.

    Based on this research, I think it is best to eliminate the need for full path and simply set the include path in the PHP ini file

    Code:
    include_path = ".;C:\webSpace\Library"
    Multiple locations/folders/paths can be added to this path statement. Of course if you have many locations each with many files it may be more efficient to use the full path but use the single quote instead of the double quote to enclose your statement.

    Comment

    Working...