xref: /PHP-8.1/Zend/tests/dereference_012.phpt (revision f8d79582)
1--TEST--
2Testing array dereferencing on return of a method with and without reference
3--FILE--
4<?php
5
6class foo {
7    static $x = array();
8
9    public function &a() {
10        self::$x = array(1, 2, 3);
11        return self::$x;
12    }
13
14    public function b() {
15        $x = array(1);
16        $x[] = 2;
17        return $x;
18    }
19}
20
21$foo = new foo;
22
23// Changing the static variable
24$foo->a()[0] = 2;
25var_dump($foo::$x);
26
27$foo->b()[] = new stdClass;
28
29$h = $foo->b();
30var_dump($h);
31
32$h[0] = 3;
33var_dump($h);
34
35?>
36--EXPECT--
37array(3) {
38  [0]=>
39  int(2)
40  [1]=>
41  int(2)
42  [2]=>
43  int(3)
44}
45array(2) {
46  [0]=>
47  int(1)
48  [1]=>
49  int(2)
50}
51array(2) {
52  [0]=>
53  int(3)
54  [1]=>
55  int(2)
56}
57