Skip to content

Commit 7a6dcec

Browse files
committed
Test wrapping const-expr closures in an array and new-expr
1 parent a96398e commit 7a6dcec

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

0 commit comments

Comments
 (0)