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"] !== b"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}
100
101if (!stream_wrapper_register("test", "mystream")) {
102	die("test wrapper registration failed");
103}
104
105echo file_get_contents("test://GLOBALS/data1");
106include("test://GLOBALS/data1");
107include_once("test://GLOBALS/data2");
108include_once("test://GLOBALS/data2");
109$include_path = get_include_path();
110set_include_path($include_path . PATH_SEPARATOR . "test://GLOBALS");
111echo file_get_contents("data3", true);
112include("data3");
113include_once("data4");
114include_once("data4");
115set_include_path("test://GLOBALS"  . PATH_SEPARATOR .  $include_path);
116echo file_get_contents("data5", true);
117include("data5");
118include_once("data6");
119include_once("data6");
120?>
121--EXPECT--
122<?php echo __FILE__ . "\n";?>
123test://GLOBALS/data1
124test://GLOBALS/data2
125<?php echo __FILE__ . "\n";?>
126test://GLOBALS/data3
127test://GLOBALS/data4
128<?php echo __FILE__ . "\n";?>
129test://GLOBALS/data5
130test://GLOBALS/data6
131