Skip to content

Instantly share code, notes, and snippets.

@robbanl
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbanl/d629bf749d7de7d1999e to your computer and use it in GitHub Desktop.
Save robbanl/d629bf749d7de7d1999e to your computer and use it in GitHub Desktop.
PHP bug with opendir-function
<?php
/**
* This is tested with PHP 5.3.10 (Ubuntu), 5.5.14 (OS X) 5.5.9 (Ubuntu).
* Instead of opendir-function you should use "DirectoryIterator" class.
*
* Save the file in /tmp/foo.php and create the following folders
*
* mkdir -p /tmp/1/2/3
* touch /tmp/1/2/3/first
* touch /tmp/1/2/3/second
*
* Run the script and it should output above 2 files and "." and ".."
*
* Now create a folder called "0" (zero)
* mkdir -p /tmp/1/2/3/0
*
* And run the script again. Nice output, right? :-)
*
* From what I understand this is caused due to the folder "0" is being
* interpenetrated as "false" and will cause the while-loop to end.
*/
$dir = opendir('/tmp/1/2/3/');
while ($file = readdir($dir)) {
echo $file . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment