xref: /PHP-8.1/Zend/tests/bug38779_1.phpt (revision f8d79582)
1--TEST--
2Bug #38779 (engine crashes when require()'ing file with syntax error through userspace stream wrapper)
3--FILE--
4<?php
5
6class Loader {
7    private $position;
8    private $data;
9    public function stream_open($path, $mode, $options, &$opened_path)  {
10        $this->data = '<' . "?php \n\"\";ll l\n ?" . '>';
11        $this->position = 0;
12        return true;
13    }
14    function stream_read($count) {
15        $ret = substr($this->data, $this->position, $count);
16        $this->position += strlen($ret);
17        return $ret;
18    }
19    function stream_eof() {
20        return $this->position >= strlen($this->data);
21    }
22    function stream_flush() {
23        var_dump("flush!");
24    }
25    function stream_close() {
26        @unlink(__DIR__."/bug38779.txt");
27        var_dump("close!");
28    }
29}
30stream_wrapper_register('Loader', 'Loader');
31$fp = fopen ('Loader://qqq.php', 'r');
32
33$filename = __DIR__."/bug38779.txt";
34$fp1 = fopen($filename, "w");
35fwrite($fp1, "<"."?php blah blah?".">");
36fclose($fp1);
37
38include $filename;
39
40echo "Done\n";
41?>
42--CLEAN--
43<?php
44
45$filename = __DIR__."/bug38779.txt";
46if (file_exists($filename)) {
47	@unlink(__DIR__."/bug38779.txt");
48}
49?>
50--EXPECTF--
51Parse error: %s error%sin %s on line %d
52string(6) "close!"
53