1--TEST--
2Stream wrappers in include_path
3--FILE--
4<?php
5$data1 = $data2 = $data3 = $data4 = $data5 = $data6 = <<<'EOD'
6<?php echo __FILE__ . "\n";?>
7
8EOD;
9/*<?*/
10
11class mystream
12{
13    public $path;
14    public $mode;
15    public $options;
16
17    public $position;
18    public $varname;
19
20    function url_stat($path, $flags) {
21        return array();
22    }
23
24    function stream_stat() {
25        return array();
26    }
27
28    function stream_open($path, $mode, $options, &$opened_path)
29    {
30        $this->path = $path;
31        $this->mode = $mode;
32        $this->options = $options;
33
34        $split = parse_url($path);
35        if ($split["host"] !== "GLOBALS" ||
36            empty($split["path"]) ||
37            empty($GLOBALS[substr($split["path"],1)])) {
38            return false;
39        }
40        $this->varname = substr($split["path"],1);
41
42        if (strchr($mode, 'a'))
43            $this->position = strlen($GLOBALS[$this->varname]);
44        else
45            $this->position = 0;
46
47        return true;
48    }
49
50    function stream_read($count)
51    {
52        $ret = substr($GLOBALS[$this->varname], $this->position, $count);
53        $this->position += strlen($ret);
54        return $ret;
55    }
56
57    function stream_tell()
58    {
59        return $this->position;
60    }
61
62    function stream_eof()
63    {
64        return $this->position >= strlen($GLOBALS[$this->varname]);
65    }
66
67    function stream_seek($offset, $whence)
68    {
69        switch($whence) {
70            case SEEK_SET:
71                if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
72                    $this->position = $offset;
73                    return true;
74                } else {
75                    return false;
76                }
77                break;
78            case SEEK_CUR:
79                if ($offset >= 0) {
80                    $this->position += $offset;
81                    return true;
82                } else {
83                    return false;
84                }
85                break;
86            case SEEK_END:
87                if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
88                    $this->position = strlen($GLOBALS[$this->varname]) + $offset;
89                    return true;
90                } else {
91                    return false;
92                }
93                break;
94            default:
95                return false;
96        }
97    }
98
99    function stream_set_option($option, $arg1, $arg2) {
100        return false;
101    }
102}
103
104if (!stream_wrapper_register("test", "mystream")) {
105    die("test wrapper registration failed");
106}
107
108echo file_get_contents("test://GLOBALS/data1");
109include("test://GLOBALS/data1");
110include_once("test://GLOBALS/data2");
111include_once("test://GLOBALS/data2");
112$include_path = get_include_path();
113set_include_path($include_path . PATH_SEPARATOR . "test://GLOBALS");
114echo file_get_contents("data3", true);
115include("data3");
116include_once("data4");
117include_once("data4");
118set_include_path("test://GLOBALS"  . PATH_SEPARATOR .  $include_path);
119echo file_get_contents("data5", true);
120include("data5");
121include_once("data6");
122include_once("data6");
123?>
124--EXPECT--
125<?php echo __FILE__ . "\n";?>
126test://GLOBALS/data1
127test://GLOBALS/data2
128<?php echo __FILE__ . "\n";?>
129test://GLOBALS/data3
130test://GLOBALS/data4
131<?php echo __FILE__ . "\n";?>
132test://GLOBALS/data5
133test://GLOBALS/data6
134