szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
262 stars 26 forks source link

Named arguments break add_filter/add_action callback check #194

Open marijnvdwerf opened 1 year ago

marijnvdwerf commented 1 year ago

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.
szepeviktor commented 1 year ago

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

szepeviktor commented 1 year ago

A second thought. Explicit is better than implicit.

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

source

szepeviktor commented 1 year ago

A third thought!

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

source