Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 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
Priority: low Milestone: 4.4
Component: I18N Version: 2.3
Severity: minor Keywords: has-patch
Cc: Focuses:

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

Download all attachments as: .zip

Change History (7)

#1 @DrewAPicture
12 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
12 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.
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?

Version 0, edited 12 years ago by pauldewouters (next)

#3 @iseulde
12 years ago

  • Keywords reporter-feedback removed

#4 @helen
11 years ago

  • Priority normal → low
  • Severity normal → minor
  • Version trunk → 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
11 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → closed

In 35092:

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

Props pauldewouters.
Fixes #31553.

#6 @SergeyBiryukov
11 years ago

  • Milestone Awaiting Review → 4.4
Note: See TracTickets for help on using tickets.