Skip to content

realpath() and SplFileInfo::getRealPath inside Phar #14481

Open
@murrant

Description

@murrant

Description

I'm trying to include packages in my phar but many of them use realpath to files inside the Phar which spits out false instead of a path; breaking things. If the behavior was to return the same path when the path starts with phar:// it would just work.

The following code:

make_phar.php

<?php
$phar = new Phar('test.phar');
$phar->addFile('test.php');
$phar->setDefaultStub('test.php');
$phar->stopBuffering();

test.php

<?php
var_dump(
    __FILE__,
    realpath(__FILE__), 
    (new SplFileInfo(__FILE__))->getRealPath(),
);

php test.php && php make_phar.php && php test.phar

Resulted in this output:

string(45) "/home/murrant/projects/realpath_test/test.php"
string(45) "/home/murrant/projects/realpath_test/test.php"
string(45) "/home/murrant/projects/realpath_test/test.php"
string(62) "phar:///home/murrant/projects/realpath_test/test.phar/test.php"
bool(false)
bool(false)

But I expected this output instead:

string(45) "/home/murrant/projects/realpath_test/test.php"
string(45) "/home/murrant/projects/realpath_test/test.php"
string(45) "/home/murrant/projects/realpath_test/test.php"
string(62) "phar:///home/murrant/projects/realpath_test/test.phar/test.php"
string(62) "phar:///home/murrant/projects/realpath_test/test.phar/test.php"
string(62) "phar:///home/murrant/projects/realpath_test/test.phar/test.php"

PHP Version

PHP 8.3.7

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions