I18N: Initialize WP_Locale array properties.

Initializing the `WP_Locale` array properties to an empty array at the class definition point. Why?

* Ensure the properties initialize to an `array` data type at instantiation (rather than `null`).

This initialization is needed to ensure the properties are not `null` if another class inherits from `WP_Locale` but does not run `WP_Locale::init()` from the constructor. In this case, the initialization prevents

{{{
Warning: array_values() expects parameter 1 to be array, null given
}}}

when Core uses any of the properties.

* Good design practice.

The code and documentation are clearly expecting these properties to be an `array` data type. Setting each to a default `array()` state further helps to clearly communicate the code design.

Follow-up to [37889], [36292], [31078], [3676], [6589].

Props tyxla, SergeyBiryukov, azaozz, hellofromTonya, mukesh27.
See #57427.
Built from https://develop.svn.wordpress.org/trunk@55047


git-svn-id: http://core.svn.wordpress.org/trunk@54580 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2023-01-10 14:00:36 +00:00
parent 924f204630
commit 07a0b36562
2 changed files with 17 additions and 9 deletions

View File

@ -19,9 +19,10 @@ class WP_Locale {
* Stores the translated strings for the full weekday names.
*
* @since 2.1.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $weekday;
public $weekday = array();
/**
* Stores the translated strings for the one character weekday names.
@ -32,41 +33,46 @@ class WP_Locale {
* @see WP_Locale::init() for how to handle the hack.
*
* @since 2.1.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $weekday_initial;
public $weekday_initial = array();
/**
* Stores the translated strings for the abbreviated weekday names.
*
* @since 2.1.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $weekday_abbrev;
public $weekday_abbrev = array();
/**
* Stores the translated strings for the full month names.
*
* @since 2.1.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $month;
public $month = array();
/**
* Stores the translated strings for the month names in genitive case, if the locale specifies.
*
* @since 4.4.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $month_genitive;
public $month_genitive = array();
/**
* Stores the translated strings for the abbreviated month names.
*
* @since 2.1.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $month_abbrev;
public $month_abbrev = array();
/**
* Stores the translated strings for 'am' and 'pm'.
@ -74,9 +80,10 @@ class WP_Locale {
* Also the capitalized versions.
*
* @since 2.1.0
* @since 6.2.0 Initialized to an empty array.
* @var string[]
*/
public $meridiem;
public $meridiem = array();
/**
* The text direction of the locale language.
@ -92,9 +99,10 @@ class WP_Locale {
* The thousands separator and decimal point values used for localizing numbers.
*
* @since 2.3.0
* @since 6.2.0 Initialized to an empty array.
* @var array
*/
public $number_format;
public $number_format = array();
/**
* The separator string used for localizing list item separator.

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-55046';
$wp_version = '6.2-alpha-55047';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.