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 */ if ('.' !== $f->getBasename() && '..' !== $f->getBasename()) { echo sprintf('pathname: %s, filename: %s', $f->getPathname(), $f->getFilename()); echo '<br />'; } }
based on cjR99
Output for 5.3.0 - 5.4.35, 5.4.38 - 5.5.24, 5.6.11, 5.6.28, 7.0.14 - 7.1.0
pathname: /tmp/test/mydir, filename: mydir<br />
Output for 5.5.25 - 5.5.26, 5.5.29, 5.6.8 - 5.6.10, 5.6.13, 5.6.21, 7.0.2, 7.0.4 - 7.0.6
pathname: /tmp/test/folder, filename: folder<br />pathname: /tmp/test/mydir, filename: mydir<br />
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/McXa6 on line 8 Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/tmp/test): failed to open dir: Not a directory in /in/McXa6:30 Stack trace: #0 /in/McXa6(30): RecursiveDirectoryIterator->__construct('/tmp/test', 4096) #1 {main} thrown in /in/McXa6 on line 30
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Warning: touch(): Unable to create file /tmp/test/.anyhidden because Not a directory in /in/McXa6 on line 8 Fatal error: Uncaught exception 'UnexpectedValueException' with message 'DirectoryIterator::__construct(/tmp/test): failed to open dir' in /in/McXa6:30 Stack trace: #0 /in/McXa6(30): RecursiveDirectoryIterator->__construct() #1 {main}
Process exited with code 255.
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/McXa6 on line 8 Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/tmp/test): failed to open dir: Not a directory' in /in/McXa6:30 Stack trace: #0 /in/McXa6(30): RecursiveDirectoryIterator->__construct('/tmp/test', 4096) #1 {main} thrown in /in/McXa6 on line 30
Process exited with code 255.
Output for 5.4.36 - 5.4.37
pathname: /tmp/test/mydir, filename: mydir<br />pathname: /tmp/test/mydir, filename: mydir<br />
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 12 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 24 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 25 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 30 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 32 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 32 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/McXa6 on line 34 Fatal error: Class 'FilesystemIterator' not found in /in/McXa6 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/McXa6 on line 12 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/McXa6 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/McXa6 on line 12 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/McXa6 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/McXa6 on line 12 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/McXa6 on line 14
Process exited with code 255.