|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-03-07 10:11 UTC] staff at pro-unreal dot de
Description: ------------ 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 phar://my.phar/lib/Foo/Bar.php: <?php echo 'YES: ' . __FILE__; ?> /usr/share/php/Foo/Bar.php <?php echo 'You should not see this!' ?> Test /tmp/test.php: <?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! PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 13:00:01 2025 UTC |
Isnt this related to fact that PATH_SEPARATOR is ":" which occurs in "phar://" ? Try this: set_include_path('phar://my.phar/lib:/usr/share/php'); 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 ;)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.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"/hello.sh echo '#!/bin/bash > echo "hello, world!" > ' $ chmod +x "localhost:80"/hello.sh $ "localhost:80"/hello.sh hello, world! $ PATH="localhost:80" $ hello.sh -bash: hello.sh: 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) { [0]=> string(12) "localhost:80" [1]=> string(13) "localhost:443" [2]=> string(4) "/tmp" } This has also been covered in documentation bug #53687: https://bugs.php.net/bug.php?id=53687 I've reclassified this as a feature request, requesting feedback.