import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / bug38450_2.php
blobfefb3dee0a3fff7e9979b0401b115f1518ceafc1
1 <?php
3 class VariableStream {
4 var $position;
5 var $varname;
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"];
15 $this->position = 0;
17 return true;
20 function stream_read($count)
22 $ret = substr($GLOBALS[$this->varname], $this->position, $count);
23 $this->position += strlen($ret);
24 return $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);
33 return strlen($data);
36 function stream_tell()
38 return $this->position;
41 function stream_eof()
43 return $this->position >= strlen($GLOBALS[$this->varname]);
45 function stream_seek($offset, $whence)
47 switch ($whence) {
48 case SEEK_SET:
49 if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
50 $this->position = $offset;
51 return true;
52 } else {
53 return false;
55 break;
57 case SEEK_CUR:
58 if ($offset >= 0) {
59 $this->position += $offset;
60 return true;
61 } else {
62 return false;
64 break;
66 case SEEK_END:
67 if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
68 $this->position = strlen($GLOBALS[$this->varname]) + $offset;
69 return true;
70 } else {
71 return false;
73 break;
75 default:
76 return false;
81 stream_wrapper_register("var", "VariableStream")
82 or die("Failed to register protocol");
84 $myvar = "";
86 $fp = fopen("var://myvar", "r+");
88 fwrite($fp, "line1\n");
89 fwrite($fp, "line2\n");
90 fwrite($fp, "line3\n");
92 rewind($fp);
93 while (!feof($fp)) {
94 echo fgets($fp);
96 fclose($fp);
97 var_dump($myvar);
99 echo "Done\n";