xref: /PHP-8.3/ext/spl/tests/bug74478.phpt (revision c6357b80)
1--TEST--
2Bug #74478: null coalescing operator failing with SplFixedArray
3--FILE--
4<?php
5
6class MyFixedArray extends \SplFixedArray
7{
8    public function offsetExists($name): bool {
9        echo "offsetExists($name)\n";
10        return parent::offsetExists($name);
11    }
12    public function offsetGet($name): mixed {
13        echo "offsetGet($name)\n";
14        return parent::offsetGet($name);
15    }
16    public function offsetSet($name, $value): void {
17        echo "offsetSet($name)\n";
18        parent::offsetSet($name, $value);
19    }
20    public function offsetUnset($name): void {
21        echo "offsetUnset($name)\n";
22        parent::offsetUnset($name);
23    }
24
25}
26
27$fixedData = new MyFixedArray(10);
28var_dump(isset($fixedData[0][1][2]));
29var_dump(isset($fixedData[0]->foo));
30var_dump($fixedData[0] ?? 42);
31var_dump($fixedData[0][1][2] ?? 42);
32
33$fixedData[0] = new MyFixedArray(10);
34$fixedData[0][1] = new MyFixedArray(10);
35var_dump(isset($fixedData[0][1][2]));
36var_dump($fixedData[0][1][2] ?? 42);
37
38?>
39--EXPECT--
40offsetExists(0)
41bool(false)
42offsetExists(0)
43bool(false)
44offsetExists(0)
45int(42)
46offsetExists(0)
47int(42)
48offsetSet(0)
49offsetGet(0)
50offsetSet(1)
51offsetExists(0)
52offsetGet(0)
53offsetExists(1)
54offsetGet(1)
55offsetExists(2)
56bool(false)
57offsetExists(0)
58offsetGet(0)
59offsetExists(1)
60offsetGet(1)
61offsetExists(2)
62int(42)
63