Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named arguments break add_filter/add_action callback check #194

Open
marijnvdwerf opened this issue Jun 24, 2023 · 3 comments
Open

Named arguments break add_filter/add_action callback check #194

marijnvdwerf opened this issue Jun 24, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@marijnvdwerf
Copy link

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
Copy link
Owner

szepeviktor commented Jun 24, 2023

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
Copy link
Owner

A second thought. Explicit is better than implicit.

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

source

@szepeviktor szepeviktor added the enhancement New feature or request label Jun 24, 2023
@szepeviktor
Copy link
Owner

szepeviktor commented Jun 24, 2023

A third thought!

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

source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants