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