On 2012-04-19, Patrick ALLAERT <patrickalla...@php.net> wrote: > 2012/4/18 Matthew Weier O'Phinney <weierophin...@php.net> : > > My one comment, which others have raised, is readability of multiple > > commas -- TBH, at first glance it has the appearance of a mistake. I > > think those suggesting a keyword such as "default" make a good point in > > this regard -- it makes it 100% clear that you want the default value > > for the argument in that position. This also presents an improvement > > over current usage, as you're not hard-coding values in your function > > calls themselves -- particularly as the defaults could change in future > > refactors. > > I think we should only support optional parameters using the "default" > keyword as it would probably make things more consistent and less > error prone: > > function foo( $bar = "bar", $foo = "foo", $baz = "baz" ) { ... } > > foo(,,, "myBaz"); // Thinking changing the value of $baz, but there's > one too much "," and PHP won't complain because of too many arguments > used! > > Additionally, we might also want to think about > call_user_func()/call_user_func_array(). > > If for the former it could work with: > > call_user_func( "foo", , , "myBaz" ); > > What about the latter? > > call_user_func_array( "foo", [2 => "myBaz"] ); // ? Evaluating the > element at index 0 would cause a notice, but would result in a NULL, > so I would say that NULL is to be used as first parameter.
I actually would argue you shouldn't skip parameters when using call_user_func(); even with call_user_func_array(), I'd argue that named parameters is the only way I'd want to allow skipping parameters. The reason I argue this is because when dynamically calling a function, you typically don't actually know exactly what the function/method is -- and thus making any assumptions about the signature other than required parameters is simply begging for problems. <snip> > Last but not least: if skipping optional parameters is implemented, > should we consider the support of default values on the leftmost side > of functions? > > function foo( $bar = "bar", $baz ) { ... } > > It could make sense that $bar followed by $baz is semantically better > than the opposite for technical reason, and this could be called > using: > > foo( default, "baz") > or: > foo(, "baz") I'd argue no -- as required arguments should always have precedence over optional ones in the signature when it comes to position. -- Matthew Weier O'Phinney Project Lead | matt...@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php