bug27508.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. Bug #27508 (userspace wrappers have bogus eof indicator)
  3. --FILE--
  4. <?php
  5. class FileStream {
  6. public $fp;
  7. function stream_open($path, $mode, $options, &$opened_path)
  8. {
  9. $url = urldecode(substr($path, 9));
  10. $this->fp = fopen($url, $mode);
  11. return true;
  12. }
  13. function stream_read($count)
  14. {
  15. return fread($this->fp, $count);
  16. }
  17. function stream_write($data)
  18. {
  19. return fwrite($this->fp, $data);
  20. }
  21. function stream_tell()
  22. {
  23. return ftell($this->fp);
  24. }
  25. function stream_eof()
  26. {
  27. if (!$this->fp) {
  28. return true;
  29. }
  30. return feof($this->fp);
  31. }
  32. function stream_seek($offset, $whence)
  33. {
  34. return fseek($this->fp, $offset, $whence) == 0 ? true : false;
  35. }
  36. }
  37. stream_wrapper_register("myFile", "FileStream")
  38. or die("Failed to register protocol");
  39. $tmp_dir = __DIR__;
  40. $tn = tempnam($tmp_dir, 'foo');
  41. if (!$tn) {
  42. die("tempnam failed");
  43. }
  44. $fp = fopen("myFile://" . urlencode($tn), "w+");
  45. if (!$fp) {
  46. die("fopen failed");
  47. }
  48. fwrite($fp, "line1\n");
  49. fwrite($fp, "line2\n");
  50. fwrite($fp, "line3\n");
  51. debug_zval_dump(feof($fp));
  52. rewind($fp);
  53. echo ftell($fp) . "\n";
  54. debug_zval_dump(feof($fp));
  55. while ($fp && !feof($fp)) {
  56. echo fgets($fp);
  57. }
  58. fclose($fp);
  59. unlink($tn);
  60. ?>
  61. --EXPECT--
  62. bool(false)
  63. 0
  64. bool(false)
  65. line1
  66. line2
  67. line3