10 ms·
Mandatory function arguments: function foo($arg1,$arg2) { return; } foo('bar'); Warning: Missing argument 2 for foo() Lame. But omitting arg2 is
by snorkel 15y ago
Mandatory function arguments:
function foo($arg1,$arg2) { return; }
foo('bar');
Warning: Missing argument 2 for foo()
Lame. But omitting arg2 is allowed if you give it a default value:
function foo($arg1,$arg2=FALSE) { return; }
Blah. Instead I'd rather make arg2 truly optional just by testing if it's defined.
- eru 15y agoI see this as a feature. (I'd never thought I come around to defend PHP. Issue #21 has bitten me in practice.)
- rokhayakebe 15y agoWhat would the ideal language return for your function call foo('bar'). It would seem to me that missing an argument should return some sort of notice, like in the case where someone else is using it.
- snorkel 15y agoI prefer Javascript for example: JQuery's calling conventions would not be possible if function args were mandatory.
- nawariata 15y agoYou can always use func_get_args() if you truly want it that way.
- ryan-allen 15y agoOr you could just use a real programming language that has some kind of design.
- wvenable 15y agoI'm curious as what PHP couldn't do? You have default argument values and you can pass more arguments to any function. Seems that covers all the cases.
- headShrinker 15y agoI really don't mind this, I have more more control because of it. If I want the function to error out upon arg omissions, I will demand arguments. If I don't require args: function foo($arg1=null, $arg2=null) {return;} foo(); // return no error This is great for me, when I am writing an API and have some args that are required and others that are optional.