xref: /PHP-8.1/Zend/tests/dereference_003.phpt (revision f8d79582)
1--TEST--
2Testing array dereference on method calls
3--FILE--
4<?php
5
6error_reporting(E_ALL);
7
8class  foo {
9    public $x = 2;
10    public function a() {
11        $x = array();
12        $x[] = new foo;
13        return $x;
14    }
15    public function b() {
16        return array(1.2, array(new self));
17    }
18    public function c() {
19        $a = array();
20        $b = &$a;
21        $b[] = true;
22        return $a;
23    }
24    public function d() {
25        return $this->b();
26    }
27}
28
29$foo = new foo;
30
31var_dump($foo->a()[0]->x);
32var_dump($foo->a()[0]);
33var_dump($foo->b()[1][0]->a()[0]->x);
34var_dump($foo->c()[0]);
35var_dump($foo->d()[0]);
36
37?>
38--EXPECTF--
39int(2)
40object(foo)#%d (1) {
41  ["x"]=>
42  int(2)
43}
44int(2)
45bool(true)
46float(1.2)
47