3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dir = '/tmp/test'; @mkdir($dir, 0777, true); touch($dir . '/.anyhidden'); // like .DS_Store on mac... @mkdir($dir . '/mydir'); class DirFilterIterator extends \FilterIterator { public function accept() { if ($this->current()->isDir()) { return true; } return false; } } $flags = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO; //$flags |= \FilesystemIterator::SKIP_DOTS; // uncomment this line to see the bug? $it = new \RecursiveDirectoryIterator($dir, $flags); $rit = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST, 0); $rit = new DirFilterIterator($rit); $iterator = new \AppendIterator(); $iterator->append($rit); foreach ($iterator as $f) { /** * @var \SplFileInfo $f */ var_dump($f); if ('.' !== $f->getBasename() && '..' !== $f->getBasename()) { //echo sprintf('pathname: %s, filename: %s', $f->getPathname(), $f->getFilename()); //echo '<br />'; } }
based on McXa6
Output for 7.0.14 - 7.1.0
object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(11) "/tmp/test/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#12 (2) { ["pathName":"SplFileInfo":private]=> string(12) "/tmp/test/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(15) "/tmp/test/mydir" ["fileName":"SplFileInfo":private]=> string(5) "mydir" } object(SplFileInfo)#14 (2) { ["pathName":"SplFileInfo":private]=> string(17) "/tmp/test/mydir/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#15 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/mydir/.." ["fileName":"SplFileInfo":private]=> string(2) ".." }
Output for 7.0.2, 7.0.4 - 7.0.6
object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(11) "/tmp/test/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#12 (2) { ["pathName":"SplFileInfo":private]=> string(12) "/tmp/test/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(16) "/tmp/test/folder" ["fileName":"SplFileInfo":private]=> string(6) "folder" } object(SplFileInfo)#14 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/folder/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#15 (2) { ["pathName":"SplFileInfo":private]=> string(19) "/tmp/test/folder/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#14 (2) { ["pathName":"SplFileInfo":private]=> string(15) "/tmp/test/mydir" ["fileName":"SplFileInfo":private]=> string(5) "mydir" } object(SplFileInfo)#12 (2) { ["pathName":"SplFileInfo":private]=> string(17) "/tmp/test/mydir/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#13 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/mydir/.." ["fileName":"SplFileInfo":private]=> string(2) ".." }
Output for 7.0.0 - 7.0.1, 7.0.3
Warning: touch(): Unable to create file /tmp/test/.anyhidden because Not a directory in /in/d0R8o on line 8 Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/tmp/test): failed to open dir: Not a directory in /in/d0R8o:30 Stack trace: #0 /in/d0R8o(30): RecursiveDirectoryIterator->__construct('/tmp/test', 0) #1 {main} thrown in /in/d0R8o on line 30
Process exited with code 255.
Output for 5.4.36 - 5.5.24, 5.6.11, 5.6.28
object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(11) "/tmp/test/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#8 (2) { ["pathName":"SplFileInfo":private]=> string(12) "/tmp/test/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(15) "/tmp/test/mydir" ["fileName":"SplFileInfo":private]=> string(5) "mydir" } object(SplFileInfo)#9 (2) { ["pathName":"SplFileInfo":private]=> string(17) "/tmp/test/mydir/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/mydir/.." ["fileName":"SplFileInfo":private]=> string(2) ".." }
Output for 5.5.25 - 5.5.26, 5.5.29, 5.6.8 - 5.6.10, 5.6.13, 5.6.21
object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(11) "/tmp/test/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#8 (2) { ["pathName":"SplFileInfo":private]=> string(12) "/tmp/test/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(16) "/tmp/test/folder" ["fileName":"SplFileInfo":private]=> string(6) "folder" } object(SplFileInfo)#9 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/folder/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(19) "/tmp/test/folder/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#9 (2) { ["pathName":"SplFileInfo":private]=> string(15) "/tmp/test/mydir" ["fileName":"SplFileInfo":private]=> string(5) "mydir" } object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(17) "/tmp/test/mydir/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#8 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/mydir/.." ["fileName":"SplFileInfo":private]=> string(2) ".." }
Output for 5.5.27 - 5.5.28, 5.5.30 - 5.5.35, 5.6.12, 5.6.14 - 5.6.20
Warning: touch(): Unable to create file /tmp/test/.anyhidden because Not a directory in /in/d0R8o on line 8 Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/tmp/test): failed to open dir: Not a directory' in /in/d0R8o:30 Stack trace: #0 /in/d0R8o(30): RecursiveDirectoryIterator->__construct('/tmp/test', 0) #1 {main} thrown in /in/d0R8o on line 30
Process exited with code 255.
Output for 5.3.23 - 5.3.29, 5.4.5 - 5.4.35
object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(15) "/tmp/test/mydir" ["fileName":"SplFileInfo":private]=> string(5) "mydir" } object(SplFileInfo)#9 (2) { ["pathName":"SplFileInfo":private]=> string(18) "/tmp/test/mydir/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(17) "/tmp/test/mydir/." ["fileName":"SplFileInfo":private]=> string(1) "." } object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(12) "/tmp/test/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#10 (2) { ["pathName":"SplFileInfo":private]=> string(11) "/tmp/test/." ["fileName":"SplFileInfo":private]=> string(1) "." }
Output for 5.3.0 - 5.3.22, 5.4.0 - 5.4.4
object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(15) "/tmp/test/mydir" ["fileName":"SplFileInfo":private]=> string(5) "mydir" } object(SplFileInfo)#8 (2) { ["pathName":"SplFileInfo":private]=> string(12) "/tmp/test/.." ["fileName":"SplFileInfo":private]=> string(2) ".." } object(SplFileInfo)#6 (2) { ["pathName":"SplFileInfo":private]=> string(11) "/tmp/test/." ["fileName":"SplFileInfo":private]=> string(1) "." }
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 12 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 24 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 25 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 30 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 32 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 32 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 34 Fatal error: Class 'FilesystemIterator' not found in /in/d0R8o on line 24
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 12 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/d0R8o on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 12 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/d0R8o on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/d0R8o on line 12 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/d0R8o on line 14
Process exited with code 255.