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