File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed
Zend/tests/closure_const_expr Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Allow defining Closures wrapped in an array in const expressions.
3+ --FILE--
4+ <?php
5+
6+ const Closure = [static function () {
7+ echo "called " , PHP_EOL ;
8+ }, static function () {
9+ echo "also called " , PHP_EOL ;
10+ }];
11+
12+ var_dump (Closure);
13+
14+ foreach (Closure as $ closure ) {
15+ $ closure ();
16+ }
17+
18+ ?>
19+ --EXPECTF--
20+ array(2) {
21+ [0]=>
22+ object(Closure)#%d (3) {
23+ ["name"]=>
24+ string(%d) "{closure:%s:%d}"
25+ ["file"]=>
26+ string(%d) "%s"
27+ ["line"]=>
28+ int(3)
29+ }
30+ [1]=>
31+ object(Closure)#%d (3) {
32+ ["name"]=>
33+ string(%d) "{closure:%s:%d}"
34+ ["file"]=>
35+ string(%d) "%s"
36+ ["line"]=>
37+ int(5)
38+ }
39+ }
40+ called
41+ also called
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Allow defining Closures wrapped in an array in const expressions.
3+ --FILE--
4+ <?php
5+
6+ class Dummy {
7+ public function __construct (
8+ public Closure $ c ,
9+ ) {}
10+ }
11+
12+ const Closure = new Dummy (static function () {
13+ echo "called " , PHP_EOL ;
14+ });
15+
16+ var_dump (Closure);
17+
18+ (Closure->c )();
19+
20+ ?>
21+ --EXPECTF--
22+ object(Dummy)#%d (1) {
23+ ["c"]=>
24+ object(Closure)#%d (3) {
25+ ["name"]=>
26+ string(%d) "{closure:%s:%d}"
27+ ["file"]=>
28+ string(%d) "%s"
29+ ["line"]=>
30+ int(9)
31+ }
32+ }
33+ called
You can’t perform that action at this time.
0 commit comments