Last active
August 29, 2015 14:13
-
-
Save robbanl/d629bf749d7de7d1999e to your computer and use it in GitHub Desktop.
PHP bug with opendir-function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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