xref: /PHP-7.3/Zend/tests/closure_026.phpt (revision 782352c5)
1--TEST--
2Closure 026: Assigning a closure object to an array in $this
3--FILE--
4<?php
5
6class foo {
7	public function __construct() {
8		$a =& $this;
9
10		$a->a[] = function() {
11			return 1;
12		};
13
14		var_dump($this);
15
16		var_dump($this->a[0]());
17	}
18}
19
20$x = new foo;
21
22print "--------------\n";
23
24foreach ($x as $b => $c) {
25	var_dump($b, $c);
26	var_dump($c[0]());
27}
28
29?>
30--EXPECTF--
31object(foo)#%d (1) {
32  ["a"]=>
33  array(1) {
34    [0]=>
35    object(Closure)#%d (1) {
36      ["this"]=>
37      *RECURSION*
38    }
39  }
40}
41int(1)
42--------------
43string(1) "a"
44array(1) {
45  [0]=>
46  object(Closure)#%d (1) {
47    ["this"]=>
48    object(foo)#%d (1) {
49      ["a"]=>
50      array(1) {
51        [0]=>
52        *RECURSION*
53      }
54    }
55  }
56}
57int(1)
58