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

1.1       misho       1: --TEST--
                      2: ZE2 ArrayAccess::offsetSet without return
                      3: --FILE--
                      4: <?php
                      5: class object implements ArrayAccess {
                      6: 
                      7:        public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
                      8: 
                      9:        function offsetExists($index) {
                     10:                echo __METHOD__ . "($index)\n";
                     11:                return array_key_exists($index, $this->a);
                     12:        }
                     13:        function offsetGet($index) {
                     14:                echo __METHOD__ . "($index)\n";
                     15:                return $this->a[$index];
                     16:        }
                     17:        function offsetSet($index, $newval) {
                     18:                echo __METHOD__ . "($index,$newval)\n";
                     19:                /*return*/ $this->a[$index] = $newval;
                     20:        }
                     21:        function offsetUnset($index) {
                     22:                echo __METHOD__ . "($index)\n";
                     23:                unset($this->a[$index]);
                     24:        }
                     25: }
                     26: 
                     27: $obj = new Object;
                     28: 
                     29: var_dump($obj->a);
                     30: 
                     31: echo "===EMPTY===\n";
                     32: var_dump(empty($obj[0]));
                     33: var_dump(empty($obj[1]));
                     34: var_dump(empty($obj[2]));
                     35: var_dump(empty($obj['4th']));
                     36: var_dump(empty($obj['5th']));
                     37: var_dump(empty($obj[6]));
                     38: 
                     39: echo "===isset===\n";
                     40: var_dump(isset($obj[0]));
                     41: var_dump(isset($obj[1]));
                     42: var_dump(isset($obj[2]));
                     43: var_dump(isset($obj['4th']));
                     44: var_dump(isset($obj['5th']));
                     45: var_dump(isset($obj[6]));
                     46: 
                     47: echo "===offsetGet===\n";
                     48: var_dump($obj[0]);
                     49: var_dump($obj[1]);
                     50: var_dump($obj[2]);
                     51: var_dump($obj['4th']);
                     52: var_dump($obj['5th']);
                     53: var_dump($obj[6]);
                     54: 
                     55: echo "===offsetSet===\n";
                     56: echo "WRITE 1\n";
                     57: $obj[1] = 'Changed 1';
                     58: var_dump($obj[1]);
                     59: echo "WRITE 2\n";
                     60: $obj['4th'] = 'Changed 4th';
                     61: var_dump($obj['4th']);
                     62: echo "WRITE 3\n";
                     63: $obj['5th'] = 'Added 5th';
                     64: var_dump($obj['5th']);
                     65: echo "WRITE 4\n";
                     66: $obj[6] = 'Added 6';
                     67: var_dump($obj[6]);
                     68: 
                     69: var_dump($obj[0]);
                     70: var_dump($obj[2]);
                     71: 
                     72: $x = $obj[6] = 'changed 6';
                     73: var_dump($obj[6]);
                     74: var_dump($x);
                     75: 
                     76: echo "===unset===\n";
                     77: var_dump($obj->a);
                     78: unset($obj[2]);
                     79: unset($obj['4th']);
                     80: unset($obj[7]);
                     81: unset($obj['8th']);
                     82: var_dump($obj->a);
                     83: 
                     84: ?>
                     85: ===DONE===
                     86: --EXPECTF--
                     87: array(4) {
                     88:   [0]=>
                     89:   string(3) "1st"
                     90:   [1]=>
                     91:   int(1)
                     92:   [2]=>
                     93:   string(3) "3rd"
                     94:   ["4th"]=>
                     95:   int(4)
                     96: }
                     97: ===EMPTY===
                     98: object::offsetExists(0)
                     99: object::offsetGet(0)
                    100: bool(false)
                    101: object::offsetExists(1)
                    102: object::offsetGet(1)
                    103: bool(false)
                    104: object::offsetExists(2)
                    105: object::offsetGet(2)
                    106: bool(false)
                    107: object::offsetExists(4th)
                    108: object::offsetGet(4th)
                    109: bool(false)
                    110: object::offsetExists(5th)
                    111: bool(true)
                    112: object::offsetExists(6)
                    113: bool(true)
                    114: ===isset===
                    115: object::offsetExists(0)
                    116: bool(true)
                    117: object::offsetExists(1)
                    118: bool(true)
                    119: object::offsetExists(2)
                    120: bool(true)
                    121: object::offsetExists(4th)
                    122: bool(true)
                    123: object::offsetExists(5th)
                    124: bool(false)
                    125: object::offsetExists(6)
                    126: bool(false)
                    127: ===offsetGet===
                    128: object::offsetGet(0)
                    129: string(3) "1st"
                    130: object::offsetGet(1)
                    131: int(1)
                    132: object::offsetGet(2)
                    133: string(3) "3rd"
                    134: object::offsetGet(4th)
                    135: int(4)
                    136: object::offsetGet(5th)
                    137: 
                    138: Notice: Undefined index: 5th in %sarray_access_002.php on line %d
                    139: NULL
                    140: object::offsetGet(6)
                    141: 
                    142: Notice: Undefined offset: 6 in %sarray_access_002.php on line %d
                    143: NULL
                    144: ===offsetSet===
                    145: WRITE 1
                    146: object::offsetSet(1,Changed 1)
                    147: object::offsetGet(1)
                    148: string(9) "Changed 1"
                    149: WRITE 2
                    150: object::offsetSet(4th,Changed 4th)
                    151: object::offsetGet(4th)
                    152: string(11) "Changed 4th"
                    153: WRITE 3
                    154: object::offsetSet(5th,Added 5th)
                    155: object::offsetGet(5th)
                    156: string(9) "Added 5th"
                    157: WRITE 4
                    158: object::offsetSet(6,Added 6)
                    159: object::offsetGet(6)
                    160: string(7) "Added 6"
                    161: object::offsetGet(0)
                    162: string(3) "1st"
                    163: object::offsetGet(2)
                    164: string(3) "3rd"
                    165: object::offsetSet(6,changed 6)
                    166: object::offsetGet(6)
                    167: string(9) "changed 6"
                    168: string(9) "changed 6"
                    169: ===unset===
                    170: array(6) {
                    171:   [0]=>
                    172:   string(3) "1st"
                    173:   [1]=>
                    174:   string(9) "Changed 1"
                    175:   [2]=>
                    176:   string(3) "3rd"
                    177:   ["4th"]=>
                    178:   string(11) "Changed 4th"
                    179:   ["5th"]=>
                    180:   string(9) "Added 5th"
                    181:   [6]=>
                    182:   string(9) "changed 6"
                    183: }
                    184: object::offsetUnset(2)
                    185: object::offsetUnset(4th)
                    186: object::offsetUnset(7)
                    187: object::offsetUnset(8th)
                    188: array(4) {
                    189:   [0]=>
                    190:   string(3) "1st"
                    191:   [1]=>
                    192:   string(9) "Changed 1"
                    193:   ["5th"]=>
                    194:   string(9) "Added 5th"
                    195:   [6]=>
                    196:   string(9) "changed 6"
                    197: }
                    198: ===DONE===

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