Make WordPress Core


Ignore:
Timestamp:
01/10/2023 01:59:00 PM (21 months ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-locale.php

    r54867 r55047  
    2020     *
    2121     * @since 2.1.0
    22      * @var string[]
    23      */
    24     public $weekday;
     22     * @since 6.2.0 Initialized to an empty array.
     23     * @var string[]
     24     */
     25    public $weekday = array();
    2526
    2627    /**
     
    3334     *
    3435     * @since 2.1.0
    35      * @var string[]
    36      */
    37     public $weekday_initial;
     36     * @since 6.2.0 Initialized to an empty array.
     37     * @var string[]
     38     */
     39    public $weekday_initial = array();
    3840
    3941    /**
     
    4143     *
    4244     * @since 2.1.0
    43      * @var string[]
    44      */
    45     public $weekday_abbrev;
     45     * @since 6.2.0 Initialized to an empty array.
     46     * @var string[]
     47     */
     48    public $weekday_abbrev = array();
    4649
    4750    /**
     
    4952     *
    5053     * @since 2.1.0
    51      * @var string[]
    52      */
    53     public $month;
     54     * @since 6.2.0 Initialized to an empty array.
     55     * @var string[]
     56     */
     57    public $month = array();
    5458
    5559    /**
     
    5761     *
    5862     * @since 4.4.0
    59      * @var string[]
    60      */
    61     public $month_genitive;
     63     * @since 6.2.0 Initialized to an empty array.
     64     * @var string[]
     65     */
     66    public $month_genitive = array();
    6267
    6368    /**
     
    6570     *
    6671     * @since 2.1.0
    67      * @var string[]
    68      */
    69     public $month_abbrev;
     72     * @since 6.2.0 Initialized to an empty array.
     73     * @var string[]
     74     */
     75    public $month_abbrev = array();
    7076
    7177    /**
     
    7581     *
    7682     * @since 2.1.0
    77      * @var string[]
    78      */
    79     public $meridiem;
     83     * @since 6.2.0 Initialized to an empty array.
     84     * @var string[]
     85     */
     86    public $meridiem = array();
    8087
    8188    /**
     
    93100     *
    94101     * @since 2.3.0
     102     * @since 6.2.0 Initialized to an empty array.
    95103     * @var array
    96104     */
    97     public $number_format;
     105    public $number_format = array();
    98106
    99107    /**
Note: See TracChangeset for help on using the changeset viewer.