2012/4/18 Matthew Weier O'Phinney <[email protected]>:
> 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 have no clue on how to correctly support skipped default values in
that case since there is a big difference in supporting the "default"
keyword inside the method call vs. as an element of an array.
Ideas are welcome!
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")
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php