array_access_007.phpt 823 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. ZE2 ArrayAccess and [] assignment
  3. --FILE--
  4. <?php
  5. class OverloadedArray implements ArrayAccess {
  6. public $realArray;
  7. function __construct() {
  8. $this->realArray = array();
  9. }
  10. function offsetExists($index) {
  11. return array_key_exists($this->realArray, $index);
  12. }
  13. function offsetGet($index) {
  14. return $this->realArray[$index];
  15. }
  16. function offsetSet($index, $value) {
  17. if (is_null($index)) {
  18. $this->realArray[] = $value;
  19. } else {
  20. $this->realArray[$index] = $value;
  21. }
  22. }
  23. function offsetUnset($index) {
  24. unset($this->realArray[$index]);
  25. }
  26. function dump() {
  27. var_dump($this->realArray);
  28. }
  29. }
  30. $a = new OverloadedArray;
  31. $a[] = 1;
  32. $a[1] = 2;
  33. $a[2] = 3;
  34. $a[] = 4;
  35. $a->dump();
  36. ?>
  37. ===DONE===
  38. --EXPECT--
  39. array(4) {
  40. [0]=>
  41. int(1)
  42. [1]=>
  43. int(2)
  44. [2]=>
  45. int(3)
  46. [3]=>
  47. int(4)
  48. }
  49. ===DONE===