File: bug79984.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (57 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (3)
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
--TEST--
Bug #79984 (Stream filter is not called with closing arg)
--FILE--
<?php

class F extends php_user_filter
{
    public function onCreate(): bool
    {
        echo 'filter onCreate' . PHP_EOL;
        return true;
    }

    public function onClose(): void
    {
        echo 'filter onClose' . PHP_EOL;
    }

    public function filter($in, $out, &$consumed, $closing): int
    {
        while ($bucket = stream_bucket_make_writeable($in)) {
            $bucket->data = strtoupper($bucket->data);
            $consumed     += $bucket->datalen;
            stream_bucket_append($out, $bucket);
        }
        echo 'filtered ' . ($consumed ? $consumed : 0) . ' bytes';
        if ($closing) {
            echo ' and closing.';
        } else {
            echo '.';
        }
        if (feof($this->stream)) {
            echo ' Stream has reached end-of-file.';
        }
        echo PHP_EOL;
        return PSFS_PASS_ON;
    }
}

stream_filter_register('f', 'F');

$str = str_repeat('a', 8320);

$f2 = fopen('php://temp', 'r+b');
fwrite($f2, $str);
fseek($f2, 0, SEEK_SET);
stream_filter_append($f2, 'f', STREAM_FILTER_READ);
var_dump(strlen(stream_get_contents($f2)));
fclose($f2);

?>
--EXPECT--
filter onCreate
filtered 8192 bytes.
filtered 128 bytes and closing. Stream has reached end-of-file.
int(8320)
filter onClose