1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/closure_const_expr/complex_array.phpt
Tim Düsterhus f6a0bb4d04 Support Closures in constant expressions (#16458)
RFC: https://wiki.php.net/rfc/closures_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arthur Kurbidaev <artkurbidaev@gmail.com>
2024-12-02 18:25:43 +01:00

42 lines
633 B
PHP

--TEST--
Allow defining Closures wrapped in an array in const expressions.
--FILE--
<?php
const Closure = [static function () {
echo "called", PHP_EOL;
}, static function () {
echo "also called", PHP_EOL;
}];
var_dump(Closure);
foreach (Closure as $closure) {
$closure();
}
?>
--EXPECTF--
array(2) {
[0]=>
object(Closure)#%d (3) {
["name"]=>
string(%d) "{closure:%s:%d}"
["file"]=>
string(%d) "%s"
["line"]=>
int(3)
}
[1]=>
object(Closure)#%d (3) {
["name"]=>
string(%d) "{closure:%s:%d}"
["file"]=>
string(%d) "%s"
["line"]=>
int(5)
}
}
called
also called