|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-08 22:41 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 11:00:02 2025 UTC |
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" }