Skip to content

Callback throws a TypeError when checking a callable has variadic parameters #5946

@ziadoz

Description

@ziadoz
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/assertionIssues related to assertions and expectationstype/bugSomething is brokenversion/10Something affects PHPUnit 10version/11Something affects PHPUnit 11

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions