11

I have tried on PhpFiddle and the PHP version on PhpFiddle supports passing more arguments than the method expected without giving any error, but not vice versa.

In my project some of my clients' server PHP version is quite old, so I would to assure that is this behavior always supported in all versions of PHP?

1
  • No, and most internal/built-in functions object if too many arguments are passed in (See); it's only user-defined functions that silently discard spurious arguments
    – Mark Baker
    Sep 2, 2016 at 11:23

2 Answers 2

10

Passing more arguments to your classes' methods than what's defined in the method's signature is already supported in PHP 4. If you want to use the ... token, that's only supported since PHP 5.6 http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list

2
  • 1
    The link you have provided only mentions about the support of ... in PHP5.6. Is there any documentation that mentions about the support of passing more args than expected in PHP4?
    – Calvin Lau
    Sep 3, 2016 at 7:18
  • 1
    Well, I believe the function func_get_args exists exactly for that, to allow calling a function with more arguments than were defined in the signature php.net/manual/en/function.func-get-args.php That function is available since PHP 4. The PHP 4 documentation is still available for download: doc.php.net/archives/php4 Even there in the examples for func_num_args() you'll find an example that passes more arguments than defined in the function. If you download the chunked xhtml archive, you'll find it in php-chunked-xhtml/function.func-get-args.html Sep 3, 2016 at 8:15
8

When passing too many arguments to a user defined function, PHP doesn't crash.

This has previously been reported as a bug, but with the current status: WONTFIX (a problem that won't be fixed).

3
  • 3
    There are perfectly valid use cases for passing many arguments to a UDF without specifying them in the function definition, such as wehn using function_get_args(), so this certainly isn't a bug
    – Mark Baker
    Sep 2, 2016 at 11:35
  • @MarkBaker Absolutely, but you can't feel safe using it if you're not sure that it's not considered a bug and that the behavior will never be changed in future versions of PHP Nov 6, 2018 at 11:09
  • @MarkBaker the function is called func_get_args(). Just for everyone wondering why their code does not work
    – Robert
    Feb 24 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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