rfc:deprecate-implicitly-nullable-types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:deprecate-implicitly-nullable-types [2024/01/23 15:20] – Clarify wording theodorejb | rfc:deprecate-implicitly-nullable-types [2024/04/11 13:02] (current) – kocsismate | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Deprecate implicitly nullable parameter types ====== | ====== PHP RFC: Deprecate implicitly nullable parameter types ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
* Date: 2023-12-20 | * Date: 2023-12-20 | ||
* Authors: Máté Kocsis < | * Authors: Máté Kocsis < | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.4 | * Target Version: PHP 8.4 | ||
* Implementation: | * Implementation: | ||
Line 74: | Line 74: | ||
Deprecated: Implicitly marking parameter $var as nullable is deprecated, the explicit nullable type must be used instead | Deprecated: Implicitly marking parameter $var as nullable is deprecated, the explicit nullable type must be used instead | ||
</ | </ | ||
+ | |||
+ | And remove support for implicitly nullable types in PHP 9. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 79: | Line 81: | ||
Using an implicitly nullable type will emit a deprecation notice. | Using an implicitly nullable type will emit a deprecation notice. | ||
- | There exist a variety of userland | + | ==== Impact analysis and migration paths ==== |
- | nullable types to explicit nullable types. | + | |
- | One such example is the <php>nullable_type_declaration_for_default_null_value</ | + | Out of the top 2000 composer packages 880 use implicitly nullable types. [2] |
- | fixer from [[https:// | + | One explanation for such a high usage is that using implicitly nullable types |
+ | was mandated by Symfony' | ||
+ | |||
+ | However, there exist a variety of tools to automatically update | ||
+ | explicit nullable types from the <php>T $parameter = null</ | ||
+ | And Symfony used one of them to migrate their codebase, and change their coding style, | ||
+ | in anticipation of this RFC. [3] | ||
+ | |||
+ | Two such tools are [[https:// | ||
+ | with the < | ||
+ | and [[https:// | ||
+ | using the < | ||
+ | from the [[https:// | ||
+ | |||
+ | It should be noted that it is possible to ignore the commit which fixes these issues from the | ||
+ | < | ||
+ | < | ||
+ | |||
+ | This flag can also be automatically configured using: | ||
+ | < | ||
+ | git config blame.ignoreRevsFile .git-blame-ignore-revs | ||
+ | </ | ||
+ | |||
+ | One other issue which might be revealed when converting implicitly nullable types to explicit ones | ||
+ | without removing the default < | ||
+ | Which will cause a secondary deprecation notice as this was [[https:// | ||
As the < | As the < | ||
- | we deem version cross compatibility | + | the various tools available to fix this issue automatically, |
+ | and this issue being easily resolved as it requires a single change at the declaration site | ||
+ | (instead of potentially infinite call-site changes), | ||
+ | we deem this deprecation | ||
+ | |||
+ | ==== Code change examples ==== | ||
+ | |||
+ | The following example: | ||
+ | < | ||
+ | class Foo { | ||
+ | public function bar(int $x = null, float $y) { | ||
+ | // ... | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | should end up looking like: | ||
+ | < | ||
+ | class Foo { | ||
+ | public function bar(?int $x, float $y) { | ||
+ | // ... | ||
+ | } | ||
+ | } | ||
+ | </ | ||
===== Version ===== | ===== Version ===== | ||
Line 95: | Line 145: | ||
As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. | As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. | ||
- | Voting started on 2024-XX-XX and will end on 2024-XX-XX. | + | Voting started on 2024-02-28 and will end on 2024-03-13. |
<doodle title=" | <doodle title=" | ||
Line 105: | Line 155: | ||
[1] https:// | [1] https:// | ||
+ | |||
+ | [2] https:// | ||
+ | |||
+ | [3] https:// | ||
rfc/deprecate-implicitly-nullable-types.1706023242.txt.gz · Last modified: 2024/01/23 15:20 by theodorejb