mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

* Include the source location in Closure names This change makes stack traces involving Closures, especially multiple different Closures, much more useful, because it's more easily visible *which* closure was called for a given stack frame. The implementation is similar to that of anonymous classes which already include the file name and line number within their generated classname. * Update scripts/dev/bless_tests.php for closure naming * Adjust existing tests for closure naming * Adjust tests for closure naming that were not caught locally * Drop the namespace from closure names This is redundant with the included filename. * Include filename and line number as separate keys in Closure debug info * Fix test * Fix test * Include the surrounding class and function name in closure names * Fix test * Relax test expecations * Fix tests after merge * NEWS / UPGRADING
44 lines
811 B
PHP
44 lines
811 B
PHP
--TEST--
|
|
Arrow functions syntax variations
|
|
--FILE--
|
|
<?php
|
|
|
|
// By-reference argument and return
|
|
$var = 1;
|
|
$id = fn&(&$x) => $x;
|
|
$ref =& $id($var);
|
|
$ref++;
|
|
var_dump($var);
|
|
|
|
// int argument and return type
|
|
$var = 10;
|
|
$int_fn = fn(int $x): int => $x;
|
|
var_dump($int_fn($var));
|
|
try {
|
|
$int_fn("foo");
|
|
} catch (TypeError $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
$varargs = fn(?int... $args): array => $args;
|
|
var_dump($varargs(20, null, 30));
|
|
try {
|
|
$varargs(40, "foo");
|
|
} catch (TypeError $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
int(2)
|
|
int(10)
|
|
{closure:%s:%d}(): Argument #1 ($x) must be of type int, string given, called in %s on line %d
|
|
array(3) {
|
|
[0]=>
|
|
int(20)
|
|
[1]=>
|
|
NULL
|
|
[2]=>
|
|
int(30)
|
|
}
|
|
{closure:%s:%d}(): Argument #2 must be of type ?int, string given, called in %s on line %d
|