Hi internals,
I've created https://github.com/php/php-src/pull/5067 to make code like
function test($foo = null, $bar) {}
throw a warning:
Warning: Required parameter $bar follows optional parameter
Historically, having an "optional" parameter before a required one was
useful for poor man's nullable types. That is, one could write
function test(FooBar $param = null, $param2)
to get an effective
function test(?FooBar $param, $param2)
signature on old PHP versions that did not have native support for nullable
types.
Since nullable types have been available since PHP 7.1, having a required
parameter after an optional one is increasingly likely a bug rather than an
intentional workaround, so I think it would be good to throw a warning for
this case.
What do you think?
Nikita