readdir_variation2.phpt 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. Test readdir() function : usage variations - empty directories
  3. --FILE--
  4. <?php
  5. /*
  6. * Pass readdir() a directory handle pointing to an empty directory to test behaviour
  7. */
  8. echo "*** Testing readdir() : usage variations ***\n";
  9. $path = __DIR__ . '/readdir_variation2';
  10. mkdir($path);
  11. $dir_handle = opendir($path);
  12. echo "\n-- Pass an empty directory to readdir() --\n";
  13. function mysort($a,$b) {
  14. return strlen($a) > strlen($b) ? 1 : -1;
  15. }
  16. $entries = array();
  17. while(FALSE !== ($file = readdir($dir_handle))){
  18. $entries[] = $file;
  19. }
  20. closedir($dir_handle);
  21. usort($entries, "mysort");
  22. foreach($entries as $entry) {
  23. var_dump($entry);
  24. }
  25. ?>
  26. --CLEAN--
  27. <?php
  28. $path = __DIR__ . '/readdir_variation2';
  29. rmdir($path);
  30. ?>
  31. --EXPECT--
  32. *** Testing readdir() : usage variations ***
  33. -- Pass an empty directory to readdir() --
  34. string(1) "."
  35. string(2) ".."