|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61317 phar locations in include_path are ignored
Submitted: 2012-03-07 10:11 UTC Modified: 2018-06-24 04:22 UTC
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: staff at pro-unreal dot de Assigned: bishop (profile)
Status: No Feedback Package: *Directory/Filesystem functions
PHP Version: 5.3.10 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-03-07 10:11 UTC] staff at pro-unreal dot de
When including files from outside a Phar all phar:// locations in include path are ignored.

Test script:
include_path = phar://my.phar/lib:/usr/share/php

echo 'YES: ' . __FILE__;

echo 'You should not see this!'

Test /tmp/test.php:
include 'Foo/Bar.php'

php -d include_path='phar://my.phar/lib:/usr/share/php' /tmp/test.php

Expected result:
Output should be:
YES: phar://my.phar/lib/Foo/Bar.php

Actual result:
Output is:

You should not see this!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-07 10:16 UTC] staff at pro-unreal dot de
Also applies for full phar URLs (Assuming the phar exists and contains the described files). 

Replace phar://my.phar/lib with full url like phar:///tmp/my.phar/lib
 [2012-06-20 07:31 UTC] stawi at plusnet dot pl
Isnt this related to fact that PATH_SEPARATOR is ":" which occurs in "phar://" ?

Try this: 
  var_export(explode(PATH_SEPARATOR, get_include_path()));

And the result is: array(
  0 => 'phar',
  1 => '//my.phar/lib',
  2 => '/usr/share/php',

Not shure how it works inside, but for PHP programmer it inconvenient...
Some frameworks uses autoloaders which do explode() and then foreach array to find file.

I know that changing PATH_SEPARATOR to other char can break a lot of code where it was hardcored as ":", but if constans exists one should use it ;)
 [2012-06-20 11:48 UTC] staff at pro-unreal dot de
I am not sure if ':' as PATH_SEPARATOR is the problem, but it works when calling include/require from a file inside a phar.

By the way ZendFramework for example uses preg_split to avoid the explode(':', $path) issue.
 [2018-01-16 02:07 UTC]
-Status: Open +Status: Feedback -Type: Bug +Type: Feature/Change Request -Package: PHAR related +Package: *Directory/Filesystem functions -Assigned To: +Assigned To: bishop
 [2018-01-16 02:07 UTC]
Within include_path, a colon separates the individual directories to search. If a directory has a colon in its name, then the colon appears to separate paths instead of acting as part of that directory's name. Whether the directory is a phar stream context, or a plain old directory with a colon in its name, the problem exists. Thus I don't think it's an issue specific to phar.

I also don't think it's a bug in PHP, because PHP isn't alone in this strict interpretation. Consider that bash operates similarly:

$ mkdir "localhost:80"
$ > "localhost:80"/ echo '#!/bin/bash
> echo "hello, world!"
> '
$ chmod +x "localhost:80"/
$ "localhost:80"/
hello, world!
$ PATH="localhost:80"
-bash: command not found

This separator problem is not unique to paths, though. It appears in other contexts: commas in the data for a CSV file, colons in the GECOS data of /etc/passwd, etc. The usual solution is either escaping the separator or signaling the value should be treated as a single unit. For example, if the directories to search are named "localhost:80" and "localhost:443", then you might try: localhost:80\:localhost:443 or "localhost:80":"localhost:443".

It is this latter approach that might qualify for a new PHP feature. One idea that strikes me, is that we could re-use the CSV parsing state machine to also parse paths. Set the separator to colon and let the parser do its thing, re-using the quoting mechanism it provides. Here is an example implementation in userland that could be projected into engine code:

$ cat example.php
<?php var_dump(str_getcsv('"localhost:80":"localhost:443":/tmp', ':'));

$ php example.php
array(3) {
  string(12) "localhost:80"
  string(13) "localhost:443"
  string(4) "/tmp"

This has also been covered in documentation bug #53687:

I've reclassified this as a feature request, requesting feedback.
 [2018-06-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Aug 04 11:01:24 2020 UTC