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