array_access_006.phpt 712 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. ZE2 ArrayAccess and ASSIGN_OP operators (+=)
  3. --FILE--
  4. <?php
  5. class OverloadedArray implements ArrayAccess {
  6. public $realArray;
  7. function __construct() {
  8. $this->realArray = array(1,2,3);
  9. }
  10. function offsetExists($index): bool {
  11. return array_key_exists($this->realArray, $index);
  12. }
  13. function offsetGet($index): mixed {
  14. return $this->realArray[$index];
  15. }
  16. function offsetSet($index, $value): void {
  17. $this->realArray[$index] = $value;
  18. }
  19. function offsetUnset($index): void {
  20. unset($this->realArray[$index]);
  21. }
  22. }
  23. $a = new OverloadedArray;
  24. $a[1] += 10;
  25. var_dump($a[1]);
  26. echo "---Done---\n";
  27. ?>
  28. --EXPECT--
  29. int(12)
  30. ---Done---