FunctionDeclarations/RemovedOptionalBeforeRequiredParam: bug fix for nullable types by jrfnl · Pull Request #1669 · PHPCompatibility/PHPCompatibility
…nullable types The [recent RFC proposing to deprecate implicit nullable types](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types) brough an oversight in the `PHPCompatibility.FunctionDeclarations.RemovedOptionalBeforeRequiredParam` sniff to my attention. To quote [the RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types): > Even though signatures which contain an optional parameter before a required one were deprecated in PHP 8.0, the case of implicitly nullable types was left alone at that time due to BC concerns. This exclusion caused some bugs in the detection of which signatures should emit the deprecation notice. Indeed, the following signature only emits a deprecation as of PHP 8.1: > > `function bar(T1 $a, ?T2 $b = null, T3 $c) {}` > > And the signature that uses the generalized union type signature: > > `function test(T1 $a, T2|null $b = null, T3 $c) {}` > > only emits the deprecation notice properly as of PHP 8.3. At the time of writing this sniff those additional two deprecation notices were not yet in place and were therefore not taken into account. This commit updates the sniff to _also_ throw deprecation notices for these two additional code patterns. Includes unit tests safeguarding the fix. **Open question:** As PHP itself only throws deprecation notices for these patterns as of PHP 8.1 and 8.3 respectively, we _could_ consider doing the same. However, based on the description in the above mentioned RFC, the _actual_ deprecation was as of PHP 8.0 and the fact that the deprecation notices weren't thrown for these two situations was an oversight/bug in PHP, which is why I have chosen not to make this distinction in the sniff.