Skip to content

Commit b39b75c

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@58009 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e77536e commit b39b75c

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/wp-admin/includes/export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function wxr_term_meta( $term ) {
401401
*
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

407407
if ( ! empty( $post_ids ) ) {

src/wp-includes/l10n/class-wp-translation-controller.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function set_locale( string $locale ) {
9898
* @param string $locale Optional. Locale. Default current locale.
9999
* @return bool True on success, false otherwise.
100100
*/
101-
public function load_file( string $translation_file, string $textdomain = 'default', string $locale = null ): bool {
101+
public function load_file( string $translation_file, string $textdomain = 'default', ?string $locale = null ): bool {
102102
if ( null === $locale ) {
103103
$locale = $this->current_locale;
104104
}
@@ -153,7 +153,7 @@ public function load_file( string $translation_file, string $textdomain = 'defau
153153
* @param string $locale Optional. Locale. Defaults to all locales.
154154
* @return bool True on success, false otherwise.
155155
*/
156-
public function unload_file( $file, string $textdomain = 'default', string $locale = null ): bool {
156+
public function unload_file( $file, string $textdomain = 'default', ?string $locale = null ): bool {
157157
if ( is_string( $file ) ) {
158158
$file = realpath( $file );
159159
}
@@ -198,7 +198,7 @@ public function unload_file( $file, string $textdomain = 'default', string $loca
198198
* @param string $locale Optional. Locale. Defaults to all locales.
199199
* @return bool True on success, false otherwise.
200200
*/
201-
public function unload_textdomain( string $textdomain = 'default', string $locale = null ): bool {
201+
public function unload_textdomain( string $textdomain = 'default', ?string $locale = null ): bool {
202202
$unloaded = false;
203203

204204
if ( null !== $locale ) {
@@ -240,7 +240,7 @@ public function unload_textdomain( string $textdomain = 'default', string $local
240240
* @param string $locale Optional. Locale. Default current locale.
241241
* @return bool True if there are any loaded translations, false otherwise.
242242
*/
243-
public function is_textdomain_loaded( string $textdomain = 'default', string $locale = null ): bool {
243+
public function is_textdomain_loaded( string $textdomain = 'default', ?string $locale = null ): bool {
244244
if ( null === $locale ) {
245245
$locale = $this->current_locale;
246246
}
@@ -260,7 +260,7 @@ public function is_textdomain_loaded( string $textdomain = 'default', string $lo
260260
* @param string $locale Optional. Locale. Default current locale.
261261
* @return string|false Translation on success, false otherwise.
262262
*/
263-
public function translate( string $text, string $context = '', string $textdomain = 'default', string $locale = null ) {
263+
public function translate( string $text, string $context = '', string $textdomain = 'default', ?string $locale = null ) {
264264
if ( '' !== $context ) {
265265
$context .= "\4";
266266
}
@@ -294,7 +294,7 @@ public function translate( string $text, string $context = '', string $textdomai
294294
* @param string $locale Optional. Locale. Default current locale.
295295
* @return string|false Translation on success, false otherwise.
296296
*/
297-
public function translate_plural( array $plurals, int $number, string $context = '', string $textdomain = 'default', string $locale = null ) {
297+
public function translate_plural( array $plurals, int $number, string $context = '', string $textdomain = 'default', ?string $locale = null ) {
298298
if ( '' !== $context ) {
299299
$context .= "\4";
300300
}
@@ -394,7 +394,7 @@ public function get_entries( string $textdomain = 'default' ): array {
394394
* @type string[] $entries Array of translation entries.
395395
* }
396396
*/
397-
protected function locate_translation( string $singular, string $textdomain = 'default', string $locale = null ) {
397+
protected function locate_translation( string $singular, string $textdomain = 'default', ?string $locale = null ) {
398398
if ( array() === $this->loaded_translations ) {
399399
return false;
400400
}
@@ -427,7 +427,7 @@ protected function locate_translation( string $singular, string $textdomain = 'd
427427
* @param string $locale Optional. Locale. Default current locale.
428428
* @return WP_Translation_File[] List of translation files.
429429
*/
430-
protected function get_files( string $textdomain = 'default', string $locale = null ): array {
430+
protected function get_files( string $textdomain = 'default', ?string $locale = null ): array {
431431
if ( null === $locale ) {
432432
$locale = $this->current_locale;
433433
}

src/wp-includes/l10n/class-wp-translation-file.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function __construct( string $file ) {
8181
* @param string|null $filetype Optional. File type. Default inferred from file name.
8282
* @return false|WP_Translation_File
8383
*/
84-
public static function create( string $file, string $filetype = null ) {
84+
public static function create( string $file, ?string $filetype = null ) {
8585
if ( ! is_readable( $file ) ) {
8686
return false;
8787
}

src/wp-includes/media.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5499,7 +5499,7 @@ function wp_show_heic_upload_error( $plupload_settings ) {
54995499
* @param array $image_info Optional. Extended image information (passed by reference).
55005500
* @return array|false Array of image information or false on failure.
55015501
*/
5502-
function wp_getimagesize( $filename, array &$image_info = null ) {
5502+
function 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
55055505
&& ! defined( 'WP_RUN_CORE_TESTS' )

0 commit comments

Comments
 (0)