Annotation of embedaddon/php/tests/classes/array_access_003.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: ZE2 ArrayAccess::offsetGet ambiguties
                      3: --INI--
                      4: error_reporting=4095
                      5: --FILE--
                      6: <?php
                      7: class object implements ArrayAccess {
                      8: 
                      9:        public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
                     10: 
                     11:        function offsetExists($index) {
                     12:                echo __METHOD__ . "($index)\n";
                     13:                return array_key_exists($index, $this->a);
                     14:        }
                     15:        function offsetGet($index) {
                     16:                echo __METHOD__ . "($index)\n";
                     17:                switch($index) {
                     18:                case 1:
                     19:                        $a = 'foo';
                     20:                        return $a . 'Bar';
                     21:                case 2:
                     22:                        static $a=1;
                     23:                        return $a;
                     24:                }
                     25:                return $this->a[$index];
                     26:        }
                     27:        function offsetSet($index, $newval) {
                     28:                echo __METHOD__ . "($index,$newval)\n";
                     29:                if ($index==3) {
                     30:                        $this->cnt = $newval;
                     31:                }
                     32:                return $this->a[$index] = $newval;
                     33:        }
                     34:        function offsetUnset($index) {
                     35:                echo __METHOD__ . "($index)\n";
                     36:                unset($this->a[$index]);
                     37:        }
                     38: }
                     39: 
                     40: $obj = new Object;
                     41: 
                     42: var_dump($obj[1]);
                     43: var_dump($obj[2]);
                     44: $obj[2]++;
                     45: var_dump($obj[2]);
                     46: 
                     47: ?>
                     48: ===DONE===
                     49: --EXPECTF--
                     50: object::offsetGet(1)
                     51: string(6) "fooBar"
                     52: object::offsetGet(2)
                     53: int(1)
                     54: object::offsetGet(2)
                     55: 
                     56: Notice: Indirect modification of overloaded element of object has no effect in %sarray_access_003.php on line 39
                     57: object::offsetGet(2)
                     58: int(1)
                     59: ===DONE===

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