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