From dd6d4e74c15c56b21888eadc8c2208fdee2152b0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 15 Apr 2024 20:03:09 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@58009 git-svn-id: http://core.svn.wordpress.org/trunk@57480 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/export.php | 2 +- .../l10n/class-wp-translation-controller.php | 16 ++++++++-------- wp-includes/l10n/class-wp-translation-file.php | 2 +- wp-includes/media.php | 2 +- wp-includes/version.php | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php index d05f98f734..277231ad52 100644 --- a/wp-admin/includes/export.php +++ b/wp-admin/includes/export.php @@ -401,7 +401,7 @@ function export_wp( $args = array() ) { * * @param int[] $post_ids Optional. Array of post IDs to filter the query by. */ - function wxr_authors_list( array $post_ids = null ) { + function wxr_authors_list( ?array $post_ids = null ) { global $wpdb; if ( ! empty( $post_ids ) ) { diff --git a/wp-includes/l10n/class-wp-translation-controller.php b/wp-includes/l10n/class-wp-translation-controller.php index b44384c013..810dcbb052 100644 --- a/wp-includes/l10n/class-wp-translation-controller.php +++ b/wp-includes/l10n/class-wp-translation-controller.php @@ -98,7 +98,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Default current locale. * @return bool True on success, false otherwise. */ - public function load_file( string $translation_file, string $textdomain = 'default', string $locale = null ): bool { + public function load_file( string $translation_file, string $textdomain = 'default', ?string $locale = null ): bool { if ( null === $locale ) { $locale = $this->current_locale; } @@ -153,7 +153,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Defaults to all locales. * @return bool True on success, false otherwise. */ - public function unload_file( $file, string $textdomain = 'default', string $locale = null ): bool { + public function unload_file( $file, string $textdomain = 'default', ?string $locale = null ): bool { if ( is_string( $file ) ) { $file = realpath( $file ); } @@ -198,7 +198,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Defaults to all locales. * @return bool True on success, false otherwise. */ - public function unload_textdomain( string $textdomain = 'default', string $locale = null ): bool { + public function unload_textdomain( string $textdomain = 'default', ?string $locale = null ): bool { $unloaded = false; if ( null !== $locale ) { @@ -240,7 +240,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Default current locale. * @return bool True if there are any loaded translations, false otherwise. */ - public function is_textdomain_loaded( string $textdomain = 'default', string $locale = null ): bool { + public function is_textdomain_loaded( string $textdomain = 'default', ?string $locale = null ): bool { if ( null === $locale ) { $locale = $this->current_locale; } @@ -260,7 +260,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Default current locale. * @return string|false Translation on success, false otherwise. */ - public function translate( string $text, string $context = '', string $textdomain = 'default', string $locale = null ) { + public function translate( string $text, string $context = '', string $textdomain = 'default', ?string $locale = null ) { if ( '' !== $context ) { $context .= "\4"; } @@ -294,7 +294,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Default current locale. * @return string|false Translation on success, false otherwise. */ - public function translate_plural( array $plurals, int $number, string $context = '', string $textdomain = 'default', string $locale = null ) { + public function translate_plural( array $plurals, int $number, string $context = '', string $textdomain = 'default', ?string $locale = null ) { if ( '' !== $context ) { $context .= "\4"; } @@ -394,7 +394,7 @@ final class WP_Translation_Controller { * @type string[] $entries Array of translation entries. * } */ - protected function locate_translation( string $singular, string $textdomain = 'default', string $locale = null ) { + protected function locate_translation( string $singular, string $textdomain = 'default', ?string $locale = null ) { if ( array() === $this->loaded_translations ) { return false; } @@ -427,7 +427,7 @@ final class WP_Translation_Controller { * @param string $locale Optional. Locale. Default current locale. * @return WP_Translation_File[] List of translation files. */ - protected function get_files( string $textdomain = 'default', string $locale = null ): array { + protected function get_files( string $textdomain = 'default', ?string $locale = null ): array { if ( null === $locale ) { $locale = $this->current_locale; } diff --git a/wp-includes/l10n/class-wp-translation-file.php b/wp-includes/l10n/class-wp-translation-file.php index e550f9c2f0..199fdca4ab 100644 --- a/wp-includes/l10n/class-wp-translation-file.php +++ b/wp-includes/l10n/class-wp-translation-file.php @@ -81,7 +81,7 @@ abstract class WP_Translation_File { * @param string|null $filetype Optional. File type. Default inferred from file name. * @return false|WP_Translation_File */ - public static function create( string $file, string $filetype = null ) { + public static function create( string $file, ?string $filetype = null ) { if ( ! is_readable( $file ) ) { return false; } diff --git a/wp-includes/media.php b/wp-includes/media.php index 396764ff2d..081457c602 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -5499,7 +5499,7 @@ function wp_show_heic_upload_error( $plupload_settings ) { * @param array $image_info Optional. Extended image information (passed by reference). * @return array|false Array of image information or false on failure. */ -function wp_getimagesize( $filename, array &$image_info = null ) { +function wp_getimagesize( $filename, ?array &$image_info = null ) { // Don't silence errors when in debug mode, unless running unit tests. if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! defined( 'WP_RUN_CORE_TESTS' ) diff --git a/wp-includes/version.php b/wp-includes/version.php index 02548fc077..c8f69929a1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58005'; +$wp_version = '6.6-alpha-58009'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.