xref: /PHP-8.2/Zend/tests/closure_020.phpt (revision 902d6439)
1--TEST--
2Closure 020: Trying to access private property outside class
3--FILE--
4<?php
5
6class foo {
7    private $test = 3;
8    public $a;
9
10    public function x() {
11        $a = &$this;
12        $this->a = function() use (&$a) { return $a; };
13        var_dump($this->a->__invoke());
14        var_dump(is_a($this->a, 'closure'));
15        var_dump(is_callable($this->a));
16
17        return $this->a;
18    }
19}
20
21$foo = new foo;
22$y = $foo->x();
23var_dump($y()->test);
24
25?>
26--EXPECTF--
27object(foo)#%d (2) {
28  ["test":"foo":private]=>
29  int(3)
30  ["a"]=>
31  object(Closure)#%d (2) {
32    ["static"]=>
33    array(1) {
34      ["a"]=>
35      *RECURSION*
36    }
37    ["this"]=>
38    *RECURSION*
39  }
40}
41bool(true)
42bool(true)
43
44Fatal error: Uncaught Error: Cannot access private property foo::$test in %s:%d
45Stack trace:
46#0 {main}
47  thrown in %s on line %d
48