(Perhaps this question has already been asked before, but I can't find it.)
What happens if you have an argument with default value preceding an argument without default value in PHP? Just like this:
function myfunction($foo = 12, $bar) {
...
}
myfunction("hello")
with only one argument?Yes, it will output a warning, not an error, namely:
Warning: Missing argument 2 in call to myfunction() in FILE on line LINENO
If you call myfunction("hello")
, $bar
is undefined, so it will either be an empty string or NULL, and $foo = "hello"
. It will only raise a warning though, so your script will still execute.
Why don't you just switch the order of the parameters?
Edit: Here is a good explanation of why it is not possible to overload standalone functions in PHP: PHP function overloading