Annotation of embedaddon/php/ext/standard/tests/file/bug38450.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Bug #38450 (constructor is not called for classes used in userspace stream wrappers)
! 3: --FILE--
! 4: <?php
! 5:
! 6: class VariableStream {
! 7: var $position;
! 8: var $varname;
! 9:
! 10: function VariableStream($var) {
! 11: var_dump("constructor!");
! 12: }
! 13:
! 14: function stream_open($path, $mode, $options, &$opened_path)
! 15: {
! 16: $url = parse_url($path);
! 17: $this->varname = $url["host"];
! 18: $this->position = 0;
! 19:
! 20: return true;
! 21: }
! 22:
! 23: function stream_read($count)
! 24: {
! 25: $ret = substr($GLOBALS[$this->varname], $this->position, $count);
! 26: $this->position += strlen($ret);
! 27: return $ret;
! 28: }
! 29:
! 30: function stream_write($data)
! 31: {
! 32: $left = substr($GLOBALS[$this->varname], 0, $this->position);
! 33: $right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
! 34: $GLOBALS[$this->varname] = $left . $data . $right;
! 35: $this->position += strlen($data);
! 36: return strlen($data);
! 37: }
! 38:
! 39: function stream_tell()
! 40: {
! 41: return $this->position;
! 42: }
! 43:
! 44: function stream_eof()
! 45: {
! 46: return $this->position >= strlen($GLOBALS[$this->varname]);
! 47: }
! 48: function stream_seek($offset, $whence)
! 49: {
! 50: switch ($whence) {
! 51: case SEEK_SET:
! 52: if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
! 53: $this->position = $offset;
! 54: return true;
! 55: } else {
! 56: return false;
! 57: }
! 58: break;
! 59:
! 60: case SEEK_CUR:
! 61: if ($offset >= 0) {
! 62: $this->position += $offset;
! 63: return true;
! 64: } else {
! 65: return false;
! 66: }
! 67: break;
! 68:
! 69: case SEEK_END:
! 70: if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
! 71: $this->position = strlen($GLOBALS[$this->varname]) + $offset;
! 72: return true;
! 73: } else {
! 74: return false;
! 75: }
! 76: break;
! 77:
! 78: default:
! 79: return false;
! 80: }
! 81: }
! 82: }
! 83:
! 84: stream_wrapper_register("var", "VariableStream")
! 85: or die("Failed to register protocol");
! 86:
! 87: $myvar = "";
! 88:
! 89: $fp = fopen("var://myvar", "r+");
! 90:
! 91: fwrite($fp, b"line1\n");
! 92: fwrite($fp, b"line2\n");
! 93: fwrite($fp, b"line3\n");
! 94:
! 95: rewind($fp);
! 96: while (!feof($fp)) {
! 97: echo fgets($fp);
! 98: }
! 99: fclose($fp);
! 100: var_dump($myvar);
! 101:
! 102: echo "Done\n";
! 103: ?>
! 104: --EXPECTF--
! 105: Warning: Missing argument 1 for VariableStream::VariableStream() in %s on line %d
! 106: string(12) "constructor!"
! 107: line1
! 108: line2
! 109: line3
! 110: string(18) "line1
! 111: line2
! 112: line3
! 113: "
! 114: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>