WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#17299 closed defect (bug) (worksforme)

number_format_i18n improper calls

Reported by: mhitza Owned by:
Milestone: Priority: normal
Severity: trivial Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

I would recommend that in the number_format_i18n function instead of

$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_formatdecimal_point?, $wp_locale->number_formatthousands_sep? );

Force a (double) typecast on the first parameter because somewhere the function is called with a string and it just fills the apache error log with warnings.

Attachments (1)

17299.patch (674 bytes) - added by SergeyBiryukov 4 years ago.

Download all attachments as: .zip

Change History (9)

@SergeyBiryukov4 years ago

comment:1 @SergeyBiryukov4 years ago

  • Keywords has-patch added

If it's called with a string somewhere, perhaps it should be fixed there.

However I don't get warnings on PHP 5.2.14 with WP_DEBUG on, even if I pass a string directly: echo number_format_i18n('18'); or even echo number_format_i18n('test');

Since I've already created the patch while testing, I'll leave it here just in case.

comment:2 @nacin4 years ago

  • Milestone changed from Awaiting Review to 3.3

I'm seeing warnings on 5.3: "Warning: number_format() expects parameter 1 to be double, string given in wp-includes/functions.php on line 155".

comment:3 @sirzooro3 years ago

Please install Xdebug to find place number_format_i18n() is called from.

comment:4 follow-up: @westi3 years ago

We should fix where this is called.

comment:5 in reply to: ↑ 4 ; follow-up: @SergeyBiryukov3 years ago

Replying to westi:

We should fix where this is called.

I don't see any warnings in core about this (checked on PHP 5.2.14 and 5.3.3). I've briefly reviewed all calls to number_format_i18n(), and didn't find anything strange. I guess the purpose of this change is to avoid the warning if a wrong parameter is passed by a plugin or a theme.

comment:6 in reply to: ↑ 5 @westi3 years ago

Replying to SergeyBiryukov:

Replying to westi:

We should fix where this is called.

I don't see any warnings in core about this (checked on PHP 5.2.14 and 5.3.3). I've briefly reviewed all calls to number_format_i18n(), and didn't find anything strange. I guess the purpose of this change is to avoid the warning if a wrong parameter is passed by a plugin or a theme.

I don't think we should "hide" warning generated by plugin/theme bugs.

comment:7 @nacin3 years ago

  • Milestone 3.3 deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.