PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/file/glob_variation.php

http://github.com/facebook/hiphop-php
PHP | 78 lines | 37 code | 7 blank | 34 comment | 0 complexity | 1b699ae1f4e00915fb5c0b4aeaba3eb0 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype: array glob ( string $pattern [, int $flags] );
  3. Description: Find pathnames matching a pattern
  4. */
  5. echo "*** Testing glob() : usage variations ***\n";
  6. $file_path = dirname(__FILE__);
  7. // temp dir created
  8. mkdir("$file_path/glob_variation");
  9. mkdir("$file_path/glob_variation/wonder");
  10. // temp files created
  11. $fp = fopen("$file_path/glob_variation/wonder12345", "w");
  12. fclose($fp);
  13. $fp = fopen("$file_path/glob_variation/wonder;123456", "w");
  14. fclose($fp);
  15. $patterns = array (
  16. "$file_path/glob_variation/*der*",
  17. "$file_path/glob_variation/?onder*",
  18. "$file_path/glob_variation/w*der?*",
  19. "$file_path/glob_variation/*der5",
  20. "$file_path/glob_variation/??onder*",
  21. "$file_path/glob_variation/***der***",
  22. "$file_path/glob_variation/++onder*",
  23. "$file_path/glob_variation/WONDER5\0",
  24. '$file_path/glob_variation/wonder5',
  25. "$file_path/glob_variation/?wonder?",
  26. "$file_path/glob_variation/wonder?",
  27. TRUE // boolean true
  28. );
  29. $counter = 1;
  30. /* loop through $patterns to match each $pattern with the files created
  31. using glob() */
  32. foreach($patterns as $pattern) {
  33. echo "\n-- Iteration $counter --\n";
  34. var_dump( glob($pattern) ); // default arguments
  35. var_dump( glob($pattern, GLOB_MARK) );
  36. var_dump( glob($pattern, GLOB_NOSORT) );
  37. var_dump( glob($pattern, GLOB_NOCHECK) );
  38. var_dump( glob($pattern, GLOB_NOESCAPE) );
  39. var_dump( glob($pattern, GLOB_ERR) );
  40. $counter++;
  41. }
  42. echo "\n*** Testing glob() with pattern within braces ***\n";
  43. var_dump( glob("$file_path/glob_variation/*{5}", GLOB_BRACE) );
  44. // delete temp files and dir
  45. unlink("$file_path/glob_variation/wonder12345");
  46. unlink("$file_path/glob_variation/wonder;123456");
  47. rmdir("$file_path/glob_variation/wonder");
  48. rmdir("$file_path/glob_variation");
  49. echo "\n*** Testing glob() on directories ***\n";
  50. // temp dir created to check for pattern matching the sub dir created in it
  51. mkdir("$file_path/glob_variation/wonder1/wonder2", 0777, true);
  52. $counter = 1;
  53. /* loop through $patterns to match each $pattern with the directories created
  54. using glob() */
  55. foreach($patterns as $pattern) {
  56. echo "-- Iteration $counter --\n";
  57. var_dump( glob($pattern, GLOB_ONLYDIR) );
  58. $counter++;
  59. }
  60. echo "Done\n";
  61. ?>
  62. <?php error_reporting(0); ?>
  63. <?php
  64. $file_path = dirname(__FILE__);
  65. rmdir("$file_path/glob_variation/wonder1/wonder2");
  66. rmdir("$file_path/glob_variation/wonder1/");
  67. rmdir("$file_path/glob_variation/");
  68. ?>