opendir_edgecases.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Phar: test edge cases of opendir() function interception
  3. --EXTENSIONS--
  4. phar
  5. --INI--
  6. phar.readonly=0
  7. --FILE--
  8. <?php
  9. Phar::interceptFileFuncs();
  10. $fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
  11. $pname = 'phar://' . $fname;
  12. try {
  13. opendir(array());
  14. } catch (TypeError $e) {
  15. echo $e->getMessage(), "\n";
  16. }
  17. mkdir(__DIR__ . '/opendir_edgecases');
  18. chdir(__DIR__);
  19. $a = opendir('opendir_edgecases');
  20. $arr = array();
  21. while (false !== ($b = readdir($a))) {
  22. $arr[] = $b;
  23. }
  24. sort($arr);
  25. foreach ($arr as $b) {
  26. echo "$b\n";
  27. }
  28. closedir($a);
  29. file_put_contents($pname . '/foo', '<?php
  30. $context = stream_context_create();
  31. $a = opendir(".", $context);
  32. $res = array();
  33. while (false !== ($b = readdir($a))) {
  34. $res[] = $b;
  35. }
  36. sort($res);
  37. foreach ($res as $b) {
  38. echo "$b\n";
  39. }
  40. opendir("oops");
  41. ?>');
  42. include $pname . '/foo';
  43. ?>
  44. --CLEAN--
  45. <?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
  46. <?php rmdir(__DIR__ . '/opendir_edgecases');
  47. --EXPECTF--
  48. opendir(): Argument #1 ($directory) must be of type string, array given
  49. .
  50. ..
  51. foo
  52. Warning: opendir(phar://%sopendir_edgecases.phar.php/oops): Failed to open directory: %s in phar://%sopendir_edgecases.phar.php/foo on line %d