Annotation of embedaddon/php/ext/standard/tests/file/bug38450_2.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 __construct($var) {
        !            11:                throw new Exception("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, "line1\n");
        !            92: fwrite($fp, "line2\n");
        !            93: fwrite($fp, "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::__construct() in %s on line %d
        !           106: 
        !           107: Warning: fopen(var://myvar): failed to open stream: "VariableStream::stream_open" call failed in %s on line %d
        !           108: 
        !           109: Fatal error: Uncaught exception 'Exception' with message 'constructor' in %s:%d
        !           110: Stack trace:
        !           111: #0 [internal function]: VariableStream->__construct()
        !           112: #1 %s(%d): fopen('var://myvar', 'r+')
        !           113: #2 {main}
        !           114:   thrown in %s on line %d

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>