Skip to content

[PHP 8] Can no longer register a command using an array of class name and method name #5472

@TimothyBJacobs

Description

@TimothyBJacobs

The following test fails on PHP 8.

    Error: Callable ["Foo_Class","foo"] does not exist, and cannot be registered as `wp foo`.
    cwd: /var/folders/7d/mcmynw4x60v3y8nwlfz3ppg80000gn/T/wp-cli-test-run-command.feature.188-5fac2916853fc6.79146154/
    run time: 0.10461497306824
    exit status: 1
    In step `When I run `wp --require=custom-cmd.php help`'.                                                                      # vendor/wp-cli/wp-cli-tests/features/steps/when.php:29
    From scenario `Use a class method as a command'.                                                                              # features/command.feature:188
    Of feature `WP-CLI Commands'.                                                                                                 # features/command.feature

This looks to be because PHP 8 no longer considers that callable if the method isn't static.

https://3v4l.org/7Jod7

I think the fix here would be adjusting the test in WP_CLI::add_command and Dispatcher\CommandFactory::create.

Are static methods supported as command callbacks?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions