Reputation: 18046
I've seen code a few times like this
function my_func( $arg1 = '', $arg2, $arg3 ) { ...
There really is no way to use the default value for $arg
, right? Since $arg2
and more are required, you're always going to have to specify a value for $arg1
, correct? Which would mean that $arg1
would never use its default value?
Upvotes: 0
Views: 62
Reputation: 11264
yes, you are right it is wrong to do so, even though php doesn't shows any error or warning in such case but any good ide will show warning...
Upvotes: 1
Reputation: 131981
PHP throws a strict warning and it is highly discouraged. However, it behaves like the first argument isn't optional. So at all you are right: The default value is never used, except you set it yourself (what doesn't feel like a default value anymore).
Upvotes: 4