xref: /PHP-7.4/ext/spl/tests/bug62059.phpt (revision f3309173)
1--TEST--
2Bug #62059: ArrayObject and isset are not friends
3--FILE--
4<?php
5
6class MyArrayObject1 extends ArrayObject {
7    public function offsetGet($name) {
8        echo "offsetGet($name)\n";
9        return parent::offsetGet($name);
10    }
11    public function offsetExists($name) {
12        echo "offsetExists($name)\n";
13        return parent::offsetExists($name);
14    }
15}
16class MyArrayObject2 extends ArrayObject {
17    public function offsetGet($name) {
18        echo "offsetGet($name)\n";
19        return parent::offsetGet($name);
20    }
21}
22class MyArrayObject3 extends ArrayObject {
23    public function offsetExists($name) {
24        echo "offsetExists($name)\n";
25        return parent::offsetExists($name);
26    }
27}
28
29$arr = [1 => [1 => 42]];
30$ao = new ArrayObject($arr);
31var_dump(isset($ao[0][1]));
32var_dump(isset($ao[1][0]));
33var_dump(isset($ao[1][1]));
34$ao = new MyArrayObject1($arr);
35var_dump(isset($ao[0][1]));
36var_dump(isset($ao[1][0]));
37var_dump(isset($ao[1][1]));
38$ao = new MyArrayObject2($arr);
39var_dump(isset($ao[0][1]));
40var_dump(isset($ao[1][0]));
41var_dump(isset($ao[1][1]));
42$ao = new MyArrayObject3($arr);
43var_dump(isset($ao[0][1]));
44var_dump(isset($ao[1][0]));
45var_dump(isset($ao[1][1]));
46
47?>
48--EXPECT--
49bool(false)
50bool(false)
51bool(true)
52offsetExists(0)
53bool(false)
54offsetExists(1)
55offsetGet(1)
56bool(false)
57offsetExists(1)
58offsetGet(1)
59bool(true)
60bool(false)
61offsetGet(1)
62bool(false)
63offsetGet(1)
64bool(true)
65offsetExists(0)
66bool(false)
67offsetExists(1)
68bool(false)
69offsetExists(1)
70bool(true)
71