Make WordPress Core


Ignore:
Timestamp:
04/15/2024 08:01:03 PM (11 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-includes/media.php

    r57921 r58009  
    55005500 * @return array|false Array of image information or false on failure.
    55015501 */
    5502 function wp_getimagesize( $filename, array &$image_info = null ) {
     5502function wp_getimagesize( $filename, ?array &$image_info = null ) {
    55035503    // Don't silence errors when in debug mode, unless running unit tests.
    55045504    if ( defined( 'WP_DEBUG' ) && WP_DEBUG
Note: See TracChangeset for help on using the changeset viewer.