Annotation of embedaddon/php/tests/classes/array_access_004.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ZE2 ArrayAccess::offsetGet ambiguties
! 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: switch($index) {
! 16: case 1:
! 17: $a = 'foo';
! 18: return $a . 'Bar';
! 19: case 2:
! 20: static $a=1;
! 21: return $a;
! 22: }
! 23: return $this->a[$index];
! 24: }
! 25: function offsetSet($index, $newval) {
! 26: echo __METHOD__ . "($index,$newval)\n";
! 27: if ($index==3) {
! 28: $this->cnt = $newval;
! 29: }
! 30: return $this->a[$index] = $newval;
! 31: }
! 32: function offsetUnset($index) {
! 33: echo __METHOD__ . "($index)\n";
! 34: unset($this->a[$index]);
! 35: }
! 36: }
! 37:
! 38: $obj = new Object;
! 39:
! 40: var_dump($obj[1]);
! 41: var_dump($obj[2]);
! 42: $obj[2]++;
! 43: var_dump($obj[2]);
! 44:
! 45: ?>
! 46: ===DONE===
! 47: --EXPECTF--
! 48: object::offsetGet(1)
! 49: string(6) "fooBar"
! 50: object::offsetGet(2)
! 51: int(1)
! 52: object::offsetGet(2)
! 53:
! 54: Notice: Indirect modification of overloaded element of object has no effect in %sarray_access_004.php on line 39
! 55: object::offsetGet(2)
! 56: int(1)
! 57: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>