In wp-includes/plugin.php (apply_filters) there's this:

    foreach( (array) current($wp_filter[$tag]) as $the_ )
        if ( !is_null($the_['function']) ){
            $args[1] = $value;
            $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));

So if you do 9999 the function will get past more arguments than it needs? How is that a problem? If you don't need the arguments don't put them in the function declaration. Passing more arguments to a function that it's declaration would lead one to believe it accepts doesn't even cause a PHP Notice and is in fact what makes func_get_args() a useful function to use.

Is my reasoning wrong or is there a reason you wouldn't want to tell the function to pass 9999 variables to it?


The reason is that you can register native PHP functions as callbacks. Passing more parameters to them then they expect will raise a warning.

Imagine a filter that can pass 6 parameters and trim() as callback. PHP would now raise an error:

Warning: Wrong parameter count for trim() in …

Some custom callbacks might also change their behavior depending on the amount of passed arguments. That’s surely not good code, but such code exists, and it would break if WP would change its current behavior now.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.