PHP 8.4 | FunctionDeclarations/RemovedOptionalBeforeRequiredParam: flag implicitly nullable parameters by jrfnl · Pull Request #1699 · PHPCompatibility/PHPCompatibility
…ag implicitly nullable parameters Follow up on 1692 and 1694 :point_right: **Opinion needed.** > - Core: > . Implicitly nullable parameter types are now deprecated. > RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types The above mentioned deprecation also impacts this sniff, as implicitly nullable parameters were previously the one exception for the "removed optional before required parameter" deprecation. While PHP 8.4 will only flag implicitly nullable parameters with a non-nullable type with a deprecation notice about these being implicitly nullable and needing a nullable type, as soon as the nullability operator is added or the type is changed to a union type which includes `null` (and the `null` default value not removed), PHP will start throwing the deprecation notice about an optional parameter being declared before a required parameter. So, in PHP itself, one deprecation notice is effectively "hiding" behind another one. In terms of sniffs, it is considered bad practice to hide one notice behind another one as it makes the sniff output less immediately actionable. With that in mind, I'm proposing to flag implicitly nullable parameters which are declared before required parameters anyway. While this doesn't match PHP exactly, I still feel this is justified so as to provide end-users with all the information they need (both deprecations) to fix the issue properly in one go. If this would turn out to be controversial, I'd suggest lowering the severity of the issue to `3` rather than removing the change. A lower severity will hide the warning from _most_ users, but will allow discerning users to still receive it. Includes updated tests. Includes an update to the docs. Refs: * https://wiki.php.net/rfc/deprecate-implicitly-nullable-types * https://github.com/php/php-src/blob/330cc5cdb2096c5d41041eaae1f1cc0ed7e36898/UPGRADING#L271C1-L273C70 * php/php-src 12959 * php/php-src@330cc5c