WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 5 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:

Description

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 6 years ago.

Download all attachments as: .zip

Change History (7)

#1 @DrewAPicture
6 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
6 years ago

Drew,

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 6 years ago by pauldewouters (previous) (diff)

#3 @iseulde
6 years ago

  • Keywords reporter-feedback removed

#4 @helen
6 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
5 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
5 years ago

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