xref: /PHP-8.2/Zend/tests/bug78406.phpt (revision 48981f4f)
1--TEST--
2Bug #78406: Broken file includes with user-defined stream filters
3--FILE--
4<?php
5
6echo "bug\n"; // Should be transformed by filter on second include
7
8if (!class_exists(SampleFilter::class)) {
9    class SampleFilter extends php_user_filter
10    {
11        private $data = '';
12
13        public function filter($in, $out, &$consumed, $closing): int
14        {
15            while ($bucket = stream_bucket_make_writeable($in))
16            {
17                $this->data .= $bucket->data;
18            }
19
20            if ($closing || feof($this->stream))
21            {
22                $consumed = strlen($this->data);
23
24                $this->data = str_replace('bug', 'feature', $this->data);
25
26                $bucket = stream_bucket_new($this->stream, $this->data);
27                stream_bucket_append($out, $bucket);
28
29                return PSFS_PASS_ON;
30            }
31
32            return PSFS_FEED_ME;
33        }
34    }
35    stream_filter_register('sample.filter', SampleFilter::class);
36    $uri = 'php://filter/read=sample.filter/resource='. __FILE__;
37
38    include $uri; // We expect one more "feature" output at line 3
39}
40
41?>
42--EXPECT--
43bug
44feature
45