[wp-trac] [WordPress Trac] #60786: [PHP 8.4] Fix implicit nullable parameter type depcation

WordPress Trac noreply at wordpress.org
Mon Apr 15 20:01:19 UTC 2024


#60786: [PHP 8.4] Fix implicit nullable parameter type depcation
-----------------------------+--------------------------------
 Reporter:  ayeshrajans      |       Owner:  SergeyBiryukov
     Type:  defect (bug)     |      Status:  closed
 Priority:  normal           |   Milestone:  6.6
Component:  General          |     Version:
 Severity:  normal           |  Resolution:  fixed
 Keywords:  php84 has-patch  |     Focuses:  php-compatibility
-----------------------------+--------------------------------
Changes (by SergeyBiryukov):

 * owner:  (none) => SergeyBiryukov
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"58009" 58009]:
 {{{
 #!CommitTicketReference repository="" revision="58009"
 Code Modernization: Fix implicit nullable parameter type deprecation on
 PHP 8.4.

 In PHP 8.4, declaring function or method parameters with a default value
 of `null` is deprecated if the type is not nullable.

 PHP applications are recommended to ''explicitly'' declare the type as
 nullable. All type declarations that have a default value of `null`, but
 without declaring `null` in the type declaration, will emit a deprecation
 notice:
 {{{
 function test( array $value = null ) {}
 }}}
 `Deprecated: Implicitly marking parameter $value as nullable is
 deprecated, the explicit nullable type must be used instead`

 **Recommended Changes**

 Change the implicit nullable type declaration to a nullable type
 declaration, available since PHP 7.1:
 {{{#!diff
 - function test( string $test = null ) {}
 + function test( ?string $test = null ) {}
 }}}

 This commit updates the affected instances in core to use a nullable type
 declaration.

 References:
 * [https://wiki.php.net/rfc/deprecate-implicitly-nullable-types PHP RFC:
 Deprecate implicitly nullable parameter types]
 * [https://php.watch/versions/8.4/implicitly-marking-parameter-type-
 nullable-deprecated PHP.Watch: PHP 8.4: Implicitly nullable parameter
 declarations deprecated]

 Follow-up to [28731], [50552], [57337], [57985].

 Props ayeshrajans, jrf, audrasjb, jorbin.
 Fixes #60786.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60786#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list