php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45345 SPLFileInfo::getPathInfo() returns incorrect values.
Submitted: 2008-06-24 10:29 UTC Modified: 2008-07-08 22:41 UTC
From: RQuadling at GMail dot com Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.3CVS-2008-06-24 (CVS) OS: Windows XP SP2
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2008-06-24 10:29 UTC] RQuadling at GMail dot com
Description:
------------
Using RII(RID()) to traverse a directory tree.

Using ->getFileInfo() to see what it returned.

The result contains an array with 2 entries, which are based upon the directory of the object making the call and not the filename.

It might be me (hey, I've got more bogus bugs than actual ones, but I think this is a real one this time!).

I'm drawn in 2 ways for the expected results.

Either ...

1 - "pathName" and "fileName" should match getPathname() and getFilename()

or

2 - getPathInfo() should return the same values as pathinfo()



Reproduce code:
---------------
<?php
// Create a small directory structure in %TEMP%
$s_Root = getenv('TEMP') . DIRECTORY_SEPARATOR . 'RAQ1';
$s_Dir = $s_Root . DIRECTORY_SEPARATOR . 'RAQ2' . DIRECTORY_SEPARATOR . 'RAQ3' . DIRECTORY_SEPARATOR . 'RAQ4';
mkdir($s_Dir, 0777, True);

// Add a file to the new tree.
file_put_contents($s_Dir . DIRECTORY_SEPARATOR . 'test.txt', 'This is a test');

// Iterate.
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s_Root)) as $o_File)
	{
	echo 'Pathname:', $o_File->getPathname(), PHP_EOL, 'Filename:', $o_File->getFilename(), PHP_EOL;
	$a_PathInfo = $o_File->getPathinfo();
	var_dump($a_PathInfo);
	}

// Remove test files and tree.
unlink($s_Dir . DIRECTORY_SEPARATOR . 'test.txt');
rmdir($s_Dir);
rmdir(dirname($s_Dir));
rmdir(dirname(dirname($s_Dir)));
rmdir(dirname(dirname(dirname($s_Dir))));


Expected result:
----------------
D:\TEMP\RAQ1\RAQ2\RAQ3\RAQ4\test.txt
object(SplFileInfo)#8 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(22) "D:\TEMP\RAQ1\RAQ2\RAQ3\RAQ4\test.txt"
  ["fileName":"SplFileInfo":private]=>
  string(27) "test.txt"
}

pathName should match getPathname()
filename should match getFilename()

OR

splfileinfo::getPathInfo() should return the same values as pathinfo()

Actual result:
--------------
Pathname:D:\TEMP\RAQ1\RAQ2\RAQ3\RAQ4\test.txt
Filename:test.txt
object(SplFileInfo)#8 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(22) "D:\TEMP\RAQ1\RAQ2\RAQ3"
  ["fileName":"SplFileInfo":private]=>
  string(27) "D:\TEMP\RAQ1\RAQ2\RAQ3\RAQ4"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-08 22:41 UTC] colder@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 02 10:01:30 2025 UTC