fgc_edgecases.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --TEST--
  2. Phar: test edge cases of file_get_contents() 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. file_get_contents(array());
  14. } catch (TypeError $e) {
  15. echo $e->getMessage(), "\n";
  16. }
  17. chdir(__DIR__);
  18. file_put_contents($fname, "blah\n");
  19. file_put_contents("fgc_edgecases.txt", "test\n");
  20. echo file_get_contents($fname);
  21. unlink($fname);
  22. mkdir($pname . '/oops');
  23. file_put_contents($pname . '/foo/hi', '<?php
  24. echo file_get_contents("foo/" . basename(__FILE__));
  25. $context = stream_context_create();
  26. try {
  27. file_get_contents("./hi", 0, $context, 0, -1);
  28. } catch (ValueError $exception) {
  29. echo $exception->getMessage() . "\n";
  30. }
  31. echo file_get_contents("fgc_edgecases.txt");
  32. set_include_path("' . addslashes(__DIR__) . '");
  33. echo file_get_contents("fgc_edgecases.txt", true);
  34. echo file_get_contents("./hi", 0, $context);
  35. echo file_get_contents("../oops");
  36. echo file_get_contents("./hi", 0, $context, 50000);
  37. echo file_get_contents("./hi");
  38. echo file_get_contents("./hi", 0, $context, 0, 0);
  39. ?>
  40. ');
  41. include $pname . '/foo/hi';
  42. ?>
  43. --CLEAN--
  44. <?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
  45. <?php unlink(__DIR__ . '/fgc_edgecases.txt'); ?>
  46. --EXPECTF--
  47. file_get_contents(): Argument #1 ($filename) must be of type string, array given
  48. blah
  49. <?php
  50. echo file_get_contents("foo/" . basename(__FILE__));
  51. $context = stream_context_create();
  52. try {
  53. file_get_contents("./hi", 0, $context, 0, -1);
  54. } catch (ValueError $exception) {
  55. echo $exception->getMessage() . "\n";
  56. }
  57. echo file_get_contents("fgc_edgecases.txt");
  58. set_include_path("%stests");
  59. echo file_get_contents("fgc_edgecases.txt", true);
  60. echo file_get_contents("./hi", 0, $context);
  61. echo file_get_contents("../oops");
  62. echo file_get_contents("./hi", 0, $context, 50000);
  63. echo file_get_contents("./hi");
  64. echo file_get_contents("./hi", 0, $context, 0, 0);
  65. ?>
  66. file_get_contents(): Argument #5 ($length) must be greater than or equal to 0
  67. test
  68. test
  69. <?php
  70. echo file_get_contents("foo/" . basename(__FILE__));
  71. $context = stream_context_create();
  72. try {
  73. file_get_contents("./hi", 0, $context, 0, -1);
  74. } catch (ValueError $exception) {
  75. echo $exception->getMessage() . "\n";
  76. }
  77. echo file_get_contents("fgc_edgecases.txt");
  78. set_include_path("%stests");
  79. echo file_get_contents("fgc_edgecases.txt", true);
  80. echo file_get_contents("./hi", 0, $context);
  81. echo file_get_contents("../oops");
  82. echo file_get_contents("./hi", 0, $context, 50000);
  83. echo file_get_contents("./hi");
  84. echo file_get_contents("./hi", 0, $context, 0, 0);
  85. ?>
  86. Warning: file_get_contents(phar://%sfgc_edgecases.phar.php/oops): Failed to open stream: phar error: path "oops" is a directory in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
  87. Warning: file_get_contents(): Failed to seek to position 50000 in the stream in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
  88. <?php
  89. echo file_get_contents("foo/" . basename(__FILE__));
  90. $context = stream_context_create();
  91. try {
  92. file_get_contents("./hi", 0, $context, 0, -1);
  93. } catch (ValueError $exception) {
  94. echo $exception->getMessage() . "\n";
  95. }
  96. echo file_get_contents("fgc_edgecases.txt");
  97. set_include_path("%stests");
  98. echo file_get_contents("fgc_edgecases.txt", true);
  99. echo file_get_contents("./hi", 0, $context);
  100. echo file_get_contents("../oops");
  101. echo file_get_contents("./hi", 0, $context, 50000);
  102. echo file_get_contents("./hi");
  103. echo file_get_contents("./hi", 0, $context, 0, 0);
  104. ?>