xref: /php-src/ext/spl/tests/bug32134.phpt (revision c6357b80)
1--TEST--
2Bug #32134 (Overloading offsetGet/offsetSet)
3--FILE--
4<?php
5
6class myArray extends ArrayIterator
7{
8
9    public function __construct($array = array())
10    {
11        parent::__construct($array);
12    }
13
14    public function offsetGet($index): mixed
15    {
16        static $i = 0;
17        echo __METHOD__ . "($index)\n";
18        if (++$i > 3) exit(1);
19        return parent::offsetGet($index);
20    }
21
22    public function offsetSet($index, $newval): void
23    {
24        echo __METHOD__ . "($index,$newval)\n";
25        parent::offsetSet($index, $newval);
26    }
27
28}
29
30$myArray = new myArray();
31
32$myArray->offsetSet('one', 'one');
33var_dump($myArray->offsetGet('one'));
34
35$myArray['two'] = 'two';
36var_dump($myArray['two']);
37
38?>
39--EXPECT--
40myArray::offsetSet(one,one)
41myArray::offsetGet(one)
42string(3) "one"
43myArray::offsetSet(two,two)
44myArray::offsetGet(two)
45string(3) "two"
46