summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/bug27508.phpt
blob: 5374a0dcbcf65d4537a0b237f193488caa41d32e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--TEST--
Bug #27508 (userspace wrappers have bogus eof indicator)
--FILE--
<?php # vim:ft=php
class FileStream {
    public $fp;
   
    function stream_open($path, $mode, $options, &$opened_path) 
    {
        $url = urldecode(substr($path, 9));
        $this->fp = fopen($url, $mode);

        return true;
    }

    function stream_read($count) 
    {
        return fread($this->fp, $count);
    }

    function stream_write($data) 
    {
        return fwrite($this->fp, $data);
    }

    function stream_tell() 
    {
        return ftell($this->fp);
    }

    function stream_eof() 
    {
        return feof($this->fp);
    }

    function stream_seek($offset, $whence) 
    {
        return fseek($this->fp, $offset, $whence) == 0 ? true : false;
    }
}

stream_wrapper_register("myFile", "FileStream")
    or die("Failed to register protocol");

$tn = tempnam('/tmp', 'foo');

$fp = fopen("myFile://" . urlencode($tn), "w+");

fwrite($fp, "line1\n");
fwrite($fp, "line2\n");
fwrite($fp, "line3\n");

debug_zval_dump(feof($fp));
rewind($fp);
echo ftell($fp) . "\n";
debug_zval_dump(feof($fp));
while (!feof($fp)) {
    echo fgets($fp);
}
fclose($fp);

unlink($tn);
--EXPECT--
bool(false) refcount(1)
0
bool(false) refcount(1)
line1
line2
line3