| Q |
A |
| PHPUnit version |
11.3.4 |
| PHP version |
8.3.7 |
| Installation Method |
Composer |
Summary
I think recent changes to the Callback class to handle variadic parameters are causing this type error:
TypeError: ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, class@anonymous given
Current behavior
The Callback class accepts a callable but it passes that to ReflectionFunction, which only accepts a Closure.
How to reproduce
You can reproduce it by directly calling the Callback class with a callable and then calling the isVariadic method:
$callback = new Callback(new class {
public function __invoke(): void
{
}
});
$callback->isVariadic();
Expected behavior
The callable should be converted to a closure before being passed to ReflectionFunction.
I do have a branch open that fixes the issue. If it looks acceptable I can open a PR for it: https://github.com/sebastianbergmann/phpunit/compare/main...ziadoz:phpunit:fix-callback-callable-variadic?expand=1
Summary
I think recent changes to the
Callbackclass to handle variadic parameters are causing this type error:Current behavior
The
Callbackclass accepts acallablebut it passes that toReflectionFunction, which only accepts aClosure.How to reproduce
You can reproduce it by directly calling the
Callbackclass with a callable and then calling theisVariadicmethod:Expected behavior
The callable should be converted to a closure before being passed to
ReflectionFunction.I do have a branch open that fixes the issue. If it looks acceptable I can open a PR for it: https://github.com/sebastianbergmann/phpunit/compare/main...ziadoz:phpunit:fix-callback-callable-variadic?expand=1