Skip to content

Instantly share code, notes, and snippets.

@robbanl

robbanl/foo.php

Last active Aug 29, 2015
Embed
What would you like to do?
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