xref: /PHP-8.3/ext/spl/tests/bug74058.phpt (revision c6357b80)
1--TEST--
2Bug #74058 (ArrayObject can not notice changes)
3--FILE--
4<?php
5
6class MyArrayObject extends ArrayObject
7{
8    public function __construct($input = [])
9    {
10        parent::__construct($input, ArrayObject::ARRAY_AS_PROPS);
11    }
12
13    public function offsetSet($x, $v): void
14    {
15        echo "offsetSet('{$x}')\n";
16        parent::offsetSet($x, $v);
17    }
18
19    public function offsetGet($x): mixed
20    {
21        echo "offsetGet('{$x}')\n";
22        return parent::offsetGet($x);
23    }
24}
25
26class MyArray extends ArrayObject
27{
28    public function __construct($input = [])
29    {
30        parent::__construct($input);
31    }
32
33    public function offsetSet($x, $v): void
34    {
35        echo "offsetSet('{$x}')\n";
36        parent::offsetSet($x, $v);
37    }
38
39    public function offsetGet($x): mixed
40    {
41        echo "offsetGet('{$x}')\n";
42        return parent::offsetGet($x);
43    }
44}
45
46$x = new MyArrayObject;
47$x->a1 = new stdClass();
48var_dump($x->a1);
49
50$x->a1->b = 'some value';
51var_dump($x->a1);
52
53$y = new MyArray();
54$y['a2'] = new stdClass();
55var_dump($y['a2']);
56
57$y['a2']->b = 'some value';
58var_dump($y['a2']);
59
60?>
61--EXPECTF--
62offsetSet('a1')
63offsetGet('a1')
64object(stdClass)#%s (0) {
65}
66offsetGet('a1')
67offsetGet('a1')
68object(stdClass)#%s (1) {
69  ["b"]=>
70  string(10) "some value"
71}
72offsetSet('a2')
73offsetGet('a2')
74object(stdClass)#%s (0) {
75}
76offsetGet('a2')
77offsetGet('a2')
78object(stdClass)#%s (1) {
79  ["b"]=>
80  string(10) "some value"
81}
82