[wp-trac] [WordPress Trac] #57427: WP_Locale doesn't initialize property arrays before using them

WordPress Trac noreply at wordpress.org
Tue Jan 10 13:59:21 UTC 2023


#57427: WP_Locale doesn't initialize property arrays before using them
-------------------------------------------------+-------------------------
 Reporter:  tyxla                                |       Owner:
                                                 |  hellofromTonya
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  6.2
Component:  I18N                                 |     Version:  6.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  testing-info commit                            |
-------------------------------------------------+-------------------------

Comment (by hellofromTonya):

 In [changeset:"55047" 55047]:
 {{{
 #!CommitTicketReference repository="" revision="55047"
 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.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57427#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list