php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71616 realpath and DirectoryIterator::getRealPath not work in phar pack file
Submitted: 2016-02-17 09:27 UTC Modified: 2021-06-22 14:16 UTC
From: janpoem at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 7.0.3 OS: Windows 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: janpoem at gmail dot com
New email:
PHP Version: OS:

 

 [2016-02-17 09:27 UTC] janpoem at gmail dot com
Description:
------------
This is a very strange question. It looks realpath returns false, but it's not. This happens in the phar file.

Test script:
---------------
<?php
/**
 * realpath not work in phar pack file
 */

$paths = [
	'phar://phar_test.phar/hello',
	'phar://phar_test.phar/hello/a.php',
];

function let_it_work(string $path)
{
	$realPath = realpath($path);
	if ($realPath !== false) {
		$path = $realPath;
	}
	return $path;
}

function show_false(string $path)
{
	return realpath($path);
}

foreach ($paths as $path) {
	var_dump(file_exists($path)); // return true
	var_dump(realpath($path)); // return false
	var_dump(let_it_work($path)); // it's work
	var_dump(show_false($path)); // return false
}

function entry(DirectoryIterator $dir = null)
{
	if ($dir === null)
		$dir = new DirectoryIterator(__DIR__);
	foreach ($dir as $item) {
		$path = $item->getPathname();
		var_dump(file_exists($path)); // true
		var_dump($item->getRealPath()); // false
	}
}

entry(new DirectoryIterator('phar://phar_test.phar'));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-22 14:16 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-06-22 14:16 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC