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

WordPress Trac noreply at wordpress.org
Fri Jan 6 13:37:35 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:  6.2
Component:  I18N          |     Version:  6.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+---------------------

Comment (by SergeyBiryukov):

 Hi there, thanks for the ticket!

 It looks like the PHP warning comes from
 [https://github.com/WordPress/gutenberg/blob/b630d7e99f94406c458275980ca87dd1a368906b/lib/compat/wordpress-6.1
 /date-settings.php#L48 these lines in Gutenberg]:
 {{{
 $scripts->add_inline_script(
         'wp-date',
         sprintf(
                 'wp.date.setSettings( %s );',
                 wp_json_encode(
                         array(
                                 'l10n'     => array(
                                         'locale'        =>
 get_user_locale(),
                                         'months'        => array_values(
 $wp_locale->month ),
                                         'monthsShort'   => array_values(
 $wp_locale->month_abbrev ),
                                         'weekdays'      => array_values(
 $wp_locale->weekday ),
                                         'weekdaysShort' => array_values(
 $wp_locale->weekday_abbrev ),
                                         'meridiem'      => (object)
 $wp_locale->meridiem,
                                         ...
                                 ),
                                 ...
                         )
                 )
         ),
         'after'
 );
 }}}

 However, I'm not quite sure exactly why, since these values should be
 [source:tags/6.1.1/src/wp-includes/class-wp-locale.php?marks=113#L107
 initialized via WP_Locale::__construct()] when the `$wp_locale` object is
 [source:tags/6.1.1/src/wp-settings.php?marks=570#L564 created in wp-
 settings.php]. Does the code in question run earlier than that?

 So the warning appears to be only indicator at the moment that the code in
 question somehow runs when the `$wp_locale` object is not fully
 initialized and the locale data is not yet available.

 * Would removing this warning make it harder to determine why the locale
 data is not loaded?
 * Should the code in question perhaps run later, when the locale data is
 initialized?

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


More information about the wp-trac mailing list