szepeviktor/phpstan-wordpress

Named arguments break add_filter/add_action callback check

marijnvdwerf opened this issue · 3 comments

Reproduce:

add_filter('filter', function($one, $two) {
    return 123;
}, accepted_args: 2);

Expected:
No errors

Actual

Callback expects 2 parameters, $accepted_args is set to 1.

Hello @marijnvdwerf! 👋🏻

Thank you for your report.
Yes, this feature of PHP is not supported.

If you take a look at the WordPress ecosystem (not core only), you see that WordPress installations should run on PHP 7.4. Maybe next year it will be 8.0 (or 8.1) compatible.
Core stats show this: https://wordpress.org/about/stats/#php_versions

A second thought. Explicit is better than implicit.

add_filter(
    'filter',
    function ($one, $two) {
        return 123;
    },
    10,
    2
);

source

A third thought!

/**
 * @hook filter
 */
public function filterHook($one, $two)
{

source