1
0
mirror of https://github.com/php/php-src.git synced 2026-04-19 05:51:02 +02:00
Files
archived-php-src/Zend/tests/arrow_functions/006.phpt
Nikita Popov b7fe1b66d0 Make argument type error message consistent for variadics
If an argument error refers to a variadic argument, we normally
do not print the name of the variadic (as it is not referring to
an individual argument, but to the collection of all of them).
However, this was not the case for the userland argument type
error message, which did it's own formatting.

Closes GH-6101.
2020-09-11 17:16:19 +02:00

45 lines
799 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}(): 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}(): Argument #2 must be of type ?int, string given, called in %s on line %d