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

WordPress Trac noreply at wordpress.org
Fri Jan 6 10:04:54 UTC 2023


#57427: WP_Locale doesn't initialize property arrays before using them
--------------------------+-----------------------------
 Reporter:  tyxla         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  6.1
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 Currently, `WP_Locale` does not initialize its internal property arrays:

 https://github.com/wordpress/wordpress-develop/blob/trunk/src/wp-includes
 /class-wp-locale.php#L24

 However, it starts using them immediately:

 https://github.com/wordpress/wordpress-develop/blob/trunk/src/wp-includes
 /class-wp-locale.php#L130

 In some setups this has caused warnings from PHP 7.4 on:

 {{{
 Warning: array_values() expects parameter 1 to be array, null given in
 /wordpress/plugins/gutenberg/14.8.4/lib/compat/wordpress-6.1/date-
 settings.php on line 48
 }}}

 This is because from PHP 7.4 on, using `null` values as arrays will
 trigger a warning:

 https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.core
 .non-array-access

 To fix this, the most straightforward way forward is to provide default
 values for all array properties in the `WP_Locale` class. That way they'll
 always be declared as arrays when we use them as such.

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


More information about the wp-trac mailing list