Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Zend/tests/trampoline_closure_named_arguments.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@ class Test {

$test = new Test;

$array = ["unpacked"];

echo "-- Non-static cases --\n";
$test->test(1, 2, a: 123);
$test->test(...)(1, 2);
$test->test(...)(1, 2, a: 123, b: $test);
$test->test(...)(a: 123, b: $test);
$test->test(...)();
$test->test(...)(...$array);

echo "-- Static cases --\n";
Test::testStatic(1, 2, a: 123);
Test::testStatic(...)(1, 2);
Test::testStatic(...)(1, 2, a: 123, b: $test);
Test::testStatic(...)(a: 123, b: $test);
Test::testStatic(...)();
Test::testStatic(...)(...$array);

echo "-- Reflection tests --\n";
$reflectionFunction = new ReflectionFunction(Test::fail(...));
var_dump($reflectionFunction->getParameters());
$argument = $reflectionFunction->getParameters()[0];
var_dump($argument->isVariadic());
$type = $argument->getType();
var_dump($type);
var_dump($type->getName());

?>
--EXPECT--
Expand Down Expand Up @@ -70,6 +83,11 @@ array(2) {
string(4) "test"
array(0) {
}
string(4) "test"
array(1) {
[0]=>
string(8) "unpacked"
}
-- Static cases --
string(10) "testStatic"
array(3) {
Expand Down Expand Up @@ -110,3 +128,20 @@ array(2) {
string(10) "testStatic"
array(0) {
}
string(10) "testStatic"
array(1) {
[0]=>
string(8) "unpacked"
}
-- Reflection tests --
array(1) {
[0]=>
object(ReflectionParameter)#4 (1) {
["name"]=>
string(9) "arguments"
}
}
bool(true)
object(ReflectionNamedType)#5 (0) {
}
string(5) "mixed"
6 changes: 6 additions & 0 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@ ZEND_API void zend_create_fake_closure(zval *res, zend_function *func, zend_clas
}
/* }}} */

/* __call and __callStatic name the arguments "$arguments" in the docs. */
static zend_internal_arg_info trampoline_arg_info[] = {ZEND_ARG_VARIADIC_TYPE_INFO(false, arguments, IS_MIXED, false)};

void zend_closure_from_frame(zval *return_value, zend_execute_data *call) { /* {{{ */
zval instance;
zend_internal_function trampoline;
Expand All @@ -856,6 +859,9 @@ void zend_closure_from_frame(zval *return_value, zend_execute_data *call) { /* {
trampoline.handler = zend_closure_call_magic;
trampoline.function_name = mptr->common.function_name;
trampoline.scope = mptr->common.scope;
if (trampoline.fn_flags & ZEND_ACC_VARIADIC) {
trampoline.arg_info = trampoline_arg_info;
}

zend_free_trampoline(mptr);
mptr = (zend_function *) &trampoline;
Expand Down