xref: /php-src/Zend/tests/bug71359.phpt (revision dab7738f)
1--TEST--
2Bug #71359: Null coalescing operator and magic
3--FILE--
4<?php
5class AA {
6    private $data = [];
7    public function __isset($name) {
8        echo "__isset($name)\n";
9        return array_key_exists($name, $this->data);
10    }
11    public function &__get($name) {
12        echo "__get($name)\n";
13        if (!array_key_exists($name, $this->data)) {
14            throw new Exception('Unknown offset');
15        }
16        return $this->data[$name];
17    }
18    public function __set($name, $value) {
19        echo "__set($name)\n";
20        $this->data[$name] = $value;
21    }
22    public function __unset($name) {
23        echo "__unset($name)\n";
24        unset($this->data[$name]);
25    }
26}
27
28$aa = new AA;
29var_dump(isset($aa->zero->one->two));
30var_dump(isset($aa->zero->foo));
31var_dump($aa->zero ?? 42);
32var_dump($aa->zero->one->two ?? 42);
33$aa->zero = new AA;
34$aa->zero->one = new AA;
35var_dump(isset($aa->zero->one->two));
36var_dump($aa->zero->one->two ?? 42);
37?>
38--EXPECT--
39__isset(zero)
40bool(false)
41__isset(zero)
42bool(false)
43__isset(zero)
44int(42)
45__isset(zero)
46int(42)
47__set(zero)
48__get(zero)
49__set(one)
50__isset(zero)
51__get(zero)
52__isset(one)
53__get(one)
54__isset(two)
55bool(false)
56__isset(zero)
57__get(zero)
58__isset(one)
59__get(one)
60__isset(two)
61int(42)
62