Make WordPress Core

Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#17299 closed defect (bug) (worksforme)

number_format_i18n improper calls

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

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

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
15 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.

#2 @nacin
15 years ago

  • Milestone Awaiting Review → 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".

#3 @sirzooro
15 years ago

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

#4 follow-up: @westi
15 years ago

We should fix where this is called.

#5 in reply to: ↑ 4 ; follow-up: @SergeyBiryukov
15 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.

#6 in reply to: ↑ 5 @westi
15 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.

#7 @nacin
15 years ago

  • Milestone 3.3
  • Resolution → worksforme
  • Status new → closed
Note: See TracTickets for help on using tickets.