7 function __construct($var) {
8 throw new Exception("constructor");
11 function stream_open($path, $mode, $options, &$opened_path)
13 $url = parse_url($path);
14 $this->varname
= $url["host"];
20 function stream_read($count)
22 $ret = substr($GLOBALS[$this->varname
], $this->position
, $count);
23 $this->position +
= strlen($ret);
27 function stream_write($data)
29 $left = substr($GLOBALS[$this->varname
], 0, $this->position
);
30 $right = substr($GLOBALS[$this->varname
], $this->position +
strlen($data));
31 $GLOBALS[$this->varname
] = $left . $data . $right;
32 $this->position +
= strlen($data);
36 function stream_tell()
38 return $this->position
;
43 return $this->position
>= strlen($GLOBALS[$this->varname
]);
45 function stream_seek($offset, $whence)
49 if ($offset < strlen($GLOBALS[$this->varname
]) && $offset >= 0) {
50 $this->position
= $offset;
59 $this->position +
= $offset;
67 if (strlen($GLOBALS[$this->varname
]) +
$offset >= 0) {
68 $this->position
= strlen($GLOBALS[$this->varname
]) +
$offset;
81 stream_wrapper_register("var", "VariableStream")
82 or die("Failed to register protocol");
86 $fp = fopen("var://myvar", "r+");
88 fwrite($fp, "line1\n");
89 fwrite($fp, "line2\n");
90 fwrite($fp, "line3\n");