Annotation of embedaddon/php/tests/classes/array_access_005.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ZE2 ArrayAccess and sub Arrays
! 3: --FILE--
! 4: <?php
! 5:
! 6: class Peoples implements ArrayAccess {
! 7: public $person;
! 8:
! 9: function __construct() {
! 10: $this->person = array(array('name'=>'Joe'));
! 11: }
! 12:
! 13: function offsetExists($index) {
! 14: return array_key_exists($this->person, $index);
! 15: }
! 16:
! 17: function offsetGet($index) {
! 18: return $this->person[$index];
! 19: }
! 20:
! 21: function offsetSet($index, $value) {
! 22: $this->person[$index] = $value;
! 23: }
! 24:
! 25: function offsetUnset($index) {
! 26: unset($this->person[$index]);
! 27: }
! 28: }
! 29:
! 30: $people = new Peoples;
! 31:
! 32: var_dump($people->person[0]['name']);
! 33: $people->person[0]['name'] = $people->person[0]['name'] . 'Foo';
! 34: var_dump($people->person[0]['name']);
! 35: $people->person[0]['name'] .= 'Bar';
! 36: var_dump($people->person[0]['name']);
! 37:
! 38: echo "---ArrayOverloading---\n";
! 39:
! 40: $people = new Peoples;
! 41:
! 42: var_dump($people[0]);
! 43: var_dump($people[0]['name']);
! 44: var_dump($people->person[0]['name'] . 'Foo'); // impossible to assign this since we don't return references here
! 45: $x = $people[0]; // creates a copy
! 46: $x['name'] .= 'Foo';
! 47: $people[0] = $x;
! 48: var_dump($people[0]);
! 49: $people[0]['name'] = 'JoeFoo';
! 50: var_dump($people[0]['name']);
! 51: $people[0]['name'] = 'JoeFooBar';
! 52: var_dump($people[0]['name']);
! 53:
! 54: ?>
! 55: ===DONE===
! 56: --EXPECTF--
! 57: string(3) "Joe"
! 58: string(6) "JoeFoo"
! 59: string(9) "JoeFooBar"
! 60: ---ArrayOverloading---
! 61: array(1) {
! 62: ["name"]=>
! 63: string(3) "Joe"
! 64: }
! 65: string(3) "Joe"
! 66: string(6) "JoeFoo"
! 67: array(1) {
! 68: ["name"]=>
! 69: string(6) "JoeFoo"
! 70: }
! 71:
! 72: Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 46
! 73: string(6) "JoeFoo"
! 74:
! 75: Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 48
! 76: string(6) "JoeFoo"
! 77: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>