People keep calling the following invalid: function method(MyClass $param1=null, $param2)
I'm way behind the times (running 4.3.6), but take a look at how 4.3.6 behaves!: <? function method($param1=null,$param2) { print "$param1:$param2\n"; } method(1,2); method(1); ?> produces 1:2 Warning: Missing argument 2 for method() in /tmp/badopt.php on line 2 1: Notice: Undefined variable: param2 in /tmp/badopt.php on line 3 *********** *** Perfect! PHP already accepts "=null" before a mandatory *** parameter and already knows not to use the null as a *** default value if a mandatory parameter follows! That's *** exactly what you want for the type hint that allows null *** case. *********** - Todd On Tue, 2004-10-19 at 10:29, Todd Ruth wrote: > On Tue, 2004-10-19 at 02:42, Christian Schneider wrote: > > The only restrictions I see is that it makes the parameter optional as > > well (something I don't consider a problem as it is probably desirable > > in most cases anyway to be able to leave out an explicit null) and that > > it only works if no mandatory parameter follows, e.g. > > function method(MyClass $obj = null, $mandatory); > > is not possible. Not a real problem either IMHO. > > Is it an implementation difficulty that makes that example > "not possible"? If not, I don't see a problem with it. > It just means the first parameter is optional in the > sense that null is allowed. I would be allowed to > call "method(null, $param)". "method($param)" would > not be legal. In the implementation, all "optional" > parameters before the last mandatory parameter would > be required to be specified by the caller but allowed > to be null. > > I don't believe the argument that a parameter should > be allowed to be optional but not allowed to be specified > as null. If I'm allowed to leave out the argument > entirely, it doesn't do any harm to give me 2 ways to > say I'm leaving out the argument: one by actually > not providing an argument and the other by providing > a null. There is a subtle difference, but it is a > difference that is already difficult make use of in > php without func_get_args (not that that's a bad thing). > > $.02 (well, less than that) > > - Todd -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php