You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

22 years ago
22 years ago
22 years ago
22 years ago
19 years ago
19 years ago
  1. --TEST--
  2. ZE2 ArrayAccess and ASSIGN_OP operators (.=)
  3. --FILE--
  4. <?php
  5. class Peoples implements ArrayAccess {
  6. public $person;
  7. function __construct() {
  8. $this->person = array(array('name'=>'Foo'));
  9. }
  10. function offsetExists($index) {
  11. return array_key_exists($this->person, $index);
  12. }
  13. function offsetGet($index) {
  14. return $this->person[$index];
  15. }
  16. function offsetSet($index, $value) {
  17. $this->person[$index] = $value;
  18. }
  19. function offsetUnset($index) {
  20. unset($this->person[$index]);
  21. }
  22. }
  23. $people = new Peoples;
  24. var_dump($people->person[0]['name']);
  25. $people->person[0]['name'] = $people->person[0]['name'] . 'Bar';
  26. var_dump($people->person[0]['name']);
  27. $people->person[0]['name'] .= 'Baz';
  28. var_dump($people->person[0]['name']);
  29. echo "===ArrayOverloading===\n";
  30. $people = new Peoples;
  31. var_dump($people[0]['name']);
  32. $people[0]['name'] = 'FooBar';
  33. var_dump($people[0]['name']);
  34. $people[0]['name'] = $people->person[0]['name'] . 'Bar';
  35. var_dump($people[0]['name']);
  36. $people[0]['name'] .= 'Baz';
  37. var_dump($people[0]['name']);
  38. ?>
  39. ===DONE===
  40. --EXPECTF--
  41. string(3) "Foo"
  42. string(6) "FooBar"
  43. string(9) "FooBarBaz"
  44. ===ArrayOverloading===
  45. string(3) "Foo"
  46. Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 40
  47. string(3) "Foo"
  48. Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 42
  49. string(3) "Foo"
  50. Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 44
  51. string(3) "Foo"
  52. ===DONE===