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