#17299 closed defect (bug) (worksforme)
number_format_i18n improper calls
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | |
| Severity: | trivial | Keywords: | has-patch |
| 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)
Change History (9)
SergeyBiryukov — 22 months ago
comment:1
SergeyBiryukov — 22 months ago
- Keywords has-patch added
- 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".
Please install Xdebug to find place number_format_i18n() is called from.
comment:5
in reply to:
↑ 4
;
follow-up:
↓ 6
SergeyBiryukov — 20 months 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.
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.
- Milestone 3.3 deleted
- Resolution set to worksforme
- Status changed from new to closed
comment:8
SergeyBiryukov — 17 months ago
Related: #19590

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.