Req #61317 [Fbk->NoF]: phar locations in include_path are ignored

From: Date: Sun, 24 Jun 2018 04:22:31 +0000
Subject: Req #61317 [Fbk->NoF]: phar locations in include_path are ignored
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215904@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61317&edit=1 ID: 61317 Updated by: php-bugs@lists.php.net Reported by: staff at pro-unreal dot de Summary: phar locations in include_path are ignored -Status: Feedback +Status: No Feedback Type: Feature/Change Request Package: *Directory/Filesystem functions Operating System: Linux PHP Version: 5.3.10 Assigned To: bishop Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2018-01-16 02:07:17] bishop@php.net 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. ------------------------------------------------------------------------ [2012-06-20 11:48:09] 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. ------------------------------------------------------------------------ [2012-06-20 07:31:00] stawi at plusnet dot pl 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 ;) ------------------------------------------------------------------------ [2012-03-07 10:16:29] 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-03-07 10:11:28] 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! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61317&edit=1

« previous php.bugs (#215904) next »