mirror of
https://github.com/php/php-src.git
synced 2026-04-27 10:16:41 +02:00
f6a0bb4d04
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>
34 lines
495 B
PHP
34 lines
495 B
PHP
--TEST--
|
|
Allow defining Closures passed as constructor arguments in const expressions.
|
|
--FILE--
|
|
<?php
|
|
|
|
class Dummy {
|
|
public function __construct(
|
|
public Closure $c,
|
|
) {}
|
|
}
|
|
|
|
const Closure = new Dummy(static function () {
|
|
echo "called", PHP_EOL;
|
|
});
|
|
|
|
var_dump(Closure);
|
|
|
|
(Closure->c)();
|
|
|
|
?>
|
|
--EXPECTF--
|
|
object(Dummy)#%d (1) {
|
|
["c"]=>
|
|
object(Closure)#%d (3) {
|
|
["name"]=>
|
|
string(%d) "{closure:%s:%d}"
|
|
["file"]=>
|
|
string(%d) "%s"
|
|
["line"]=>
|
|
int(9)
|
|
}
|
|
}
|
|
called
|