diff --git a/tests/aot/dynamic_call/new-named-args.phpt b/tests/aot/dynamic_call/new-named-args.phpt new file mode 100644 index 00000000..d0967cac --- /dev/null +++ b/tests/aot/dynamic_call/new-named-args.phpt @@ -0,0 +1,45 @@ +--TEST-- +Dynamic instantiation with named arguments and dynamic method call +--FILE-- +prefix = $prefix; + } + + public function greet(string $name, int $times): string { + $result = ''; + for ($i = 0; $i < $times; $i++) { + $result .= "{$this->prefix} {$name}!\n"; + } + return $result; + } + + public function farewell(string $name): string { + return "{$this->prefix} Goodbye {$name}!"; + } +} + +function main(): void { + $handler = [HelloController::class, 'greet']; + $params = ['World', 2]; + + [$class, $method] = $handler; + // Dynamic instantiation with named args + dynamic method call with unpacking + $result = (new $class(prefix: 'Hi'))->$method(name: $params[0], times: $params[1]); + echo $result; + + // Another dynamic method call: farewell + $handler[1] = 'farewell'; + [$class, $method] = $handler; + echo (new $class(prefix: 'Ohayo'))->$method(name: 'AOT'); +} +?> +--EXPECT-- +Hi World! +Hi World! +Ohayo Goodbye AOT!