Warn when declaring required parameter after optional one

From: Date: Thu, 09 Jan 2020 12:26:35 +0000
Subject: Warn when declaring required parameter after optional one
Groups: php.internals 
Request: Send a blank email to internals+get-108052@lists.php.net to get a copy of this message
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

« previous php.internals (#108052) next »