Make WordPress Core


Ignore:
Timestamp:
04/15/2024 08:01:03 PM (15 months ago)
Author:
SergeyBiryukov
Message:

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:

- 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:

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/export.php

    r57681 r58009  
    402402     * @param int[] $post_ids Optional. Array of post IDs to filter the query by.
    403403     */
    404     function wxr_authors_list( array $post_ids = null ) {
     404    function wxr_authors_list( ?array $post_ids = null ) {
    405405        global $wpdb;
    406406
Note: See TracChangeset for help on using the changeset viewer.