Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#31553 closed defect (bug) (fixed)

number_format_i18n() can cause a PHP notice if $wp_locale is not set

Reported by: pauldewouters Owned by: SergeyBiryukov
Milestone: 4.4 Priority: low
Severity: minor Version: 2.3
Component: I18N Keywords: has-patch
Focuses: Cc:


It is possible for number_format_i18n to cause a PHP notice if called via timer_stop at a point where $wp_locale is not set.
This is because the function calls a method of the class without checking if it is available.
I attached a patch.

Attachments (1)

functions.diff (817 bytes) - added by pauldewouters 7 years ago.

Download all attachments as: .zip

Change History (7)

#1 @DrewAPicture
7 years ago

  • Keywords has-patch reporter-feedback added

Hi Paul, thanks for the patch.

The only issue here is really that the function specifically serves to convert a number based on the locale. So while the is_object() check would solve the problem, I'd be curious to know what your use case is where $wp_locale would not be set.

#2 @pauldewouters
7 years ago


Thanks for your comment. In my case I was calling timer_start() and then timer_stop(1) with some code in between to time it, directly on page load inside a plugin, not inside a hook and from the admin side.
Maybe this was not the expected use case for this function. However, would there not be some benefit to making the function a little more robust?

Last edited 7 years ago by pauldewouters (previous) (diff)

#3 @iseulde
7 years ago

  • Keywords reporter-feedback removed

#4 @helen
7 years ago

  • Priority changed from normal to low
  • Severity changed from normal to minor
  • Version changed from trunk to 2.3

This looks to me like it's existed since the function was introduced, so moving the version accordingly. If this really is a trunk issue somehow, please do let us know, although I don't think it's severe enough to worry about 4.2.

#5 @SergeyBiryukov
6 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 35092:

In number_format_i18n(), check if $wp_locale is set before using it.

Props pauldewouters.
Fixes #31553.

#6 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 4.4
Note: See TracTickets for help on using tickets.