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: -
From: janpoem at gmail dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 7.0.3 OS: Windows 10
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Jul 19 13:01:25 2018 UTC