php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63028 Include inside Phar with "./" prefix fails to include correctly
Submitted: 2012-09-07 08:57 UTC Modified: 2012-09-08 15:22 UTC
From: james dot turner dot phpninja at gmail dot com Assigned:
Status: Not a bug Package: PHAR related
PHP Version: 5.3.16 OS: Ubuntu 12
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: james dot turner dot phpninja at gmail dot com
New email:
PHP Version: OS:

 

 [2012-09-07 08:57 UTC] james dot turner dot phpninja at gmail dot com
Description:
------------
When including a file from another file within a phar build, that has a ./ prefix, e.g. include_once './my/other/file.php' a "failed to open stream: No such file or directory in phar" warning is thrown followed by a Fatal error "PHP Fatal error:  require_once(): Failed opening required './my/other/file.php"


The test script below contains 3 files required to produce the same output.

structure:

.
/src
/src/index.php
/src/includes/bootstrap.php
package.php

Test script:
---------------
// package.php
<?php
if(!file_exists('test.phar')){
    try {
        $phar = new Phar('test.phar');
        $phar->buildFromDirectory('src');
        $phar->setStub($phar->createDefaultStub());
    } catch(PharException $e){
        echo $e->getMessage();
    }
} else {
    require_once ('phar://test.phar');
}


// src/index.php
<?php

require_once './includes/bootstrap.php'


// src/includes/bootstrap.php
<?

echo "hello world";

Expected result:
----------------
hello world

Actual result:
--------------
/usr/bin/php /workspace/PharTest/package.php
PHP Warning:  require_once(./includes/bootstrap.php): failed to open stream: No such file or directory in phar:///workspace/PharTest/test.phar/index.php on line 3
PHP Stack trace:
PHP   1. {main}() /workspace/PharTest/package.php:0
PHP   2. require_once() /workspace/PharTest/package.php:12
PHP   3. include() /workspace/PharTest/test.phar:9
PHP Fatal error:  require_once(): Failed opening required './includes/bootstrap.php' (include_path='phar:///workspace/PharTest/test.phar:.:/usr/share/php:/usr/share/pear') in phar:///workspace/PharTest/test.phar/index.php on line 3
PHP Stack trace:
PHP   1. {main}() /workspace/PharTest/package.php:0
PHP   2. require_once() /workspace/PharTest/package.php:12
PHP   3. include() /workspace/PharTest/test.phar:9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-07 09:12 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

you should make your index.php like(which will use the include_path):

<?php
require_once 'includes/bootstrap.php'
 [2012-09-07 09:12 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-09-07 10:02 UTC] james dot turner dot phpninja at gmail dot com
While I might concur and say that this is not a "bug" as such, what i'm getting at is the fact that using "./include/a/file.php" IS valid syntax for a file include path. It works in normal PHP land, but it does not work within a Phar archive.

The issue is that I have an external library, which I wish to package up for deployment, but i'm prohibited from doing so because the library uses these "./" prefix notations on all their include paths. I do NOT want to alter the whole library and change all include paths to use a different relative syntax for file paths as this will then lead to inconsistency between the source and the version I'm using.

Given that phar archives can intercept file path related calls should it not be able to resolve "." to be the path relative to the file invoked from within the phar archive? I still believe this to be a problem...
 [2012-09-07 10:07 UTC] laruence@php.net
thinking of such structure:
.
test.phar
/include/bootstrap.php

people may want to include a file which is not in the phar..
 [2012-09-08 15:22 UTC] james dot turner dot phpninja at gmail dot com
Yes, you might want to include a file that is not in a phar (other library requirements etc etc) but given that the phar is on the include path it should look there first, it just doesn't work...
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 10 02:01:24 2020 UTC