Make WordPress Core

Opened 20 months ago

Closed 20 months ago

Last modified 6 months ago

#62474 closed enhancement (wontfix)

[ wp-includes/functions.php - number_format_i18n() ] - fallback in case number is not a float

Reported by: riccardodicurti Owned by:
Priority: normal Milestone:
Component: I18N Version:
Severity: minor Keywords: has-patch has-test-info has-screenshots dev-feedback close
Cc: Focuses:

Description

Good morning everyone, while working on a project on php 8, I found that a plugin was passing number to number_format_i18n() that was not a float and this led to an error.

In my opinion, it would therefore be better to add a check or a cast to float in order to avoid potential errors.

Thanks in advance.

Change History (9)

This ticket was mentioned in PR #7830 on WordPress/wordpress-develop by @abcd95.


20 months ago
#1

  • Keywords has-patch added

Trac ticket: Core: 62474

Currently in WordPress 6.6, passing non-numeric values to number_format_i18n() can trigger PHP errors in PHP 8. This PR adds float-type casting to safely handle all input types.

#2 @abcd95
20 months ago

  • Keywords has-testing-info has-screenshots added

Hey @riccardodicurti, Thanks for bringing this up.

I was able to reproduce this issue. The problem occurs when non-numeric values are passed to number_format_i18n().

Reproduction Steps:

Run:

number_format_i18n("abc"); Throws error

Screenshots

  • Before the patch - https://postimg.cc/Fff6Q3Kj
  • After the patch - https://postimg.cc/s10w31tm

Please let me know if we can do better!

#3 @riccardodicurti
20 months ago

Ciao @abcd95, I think this should be perfect. I tested the patch myself, and it works as expected. Thank you.

#4 @riccardodicurti
20 months ago

  • Keywords dev-feedback added

#5 @swissspidy
20 months ago

  • Keywords close added

Why not just fix the type in your plugin? Core dorsn‘t usually paper over ddvdlopers‘ issues like that by adding casts everywhere. It‘s your responsibility to pass the expected type to a function.

#6 @SergeyBiryukov
20 months ago

Hi there, thanks for the ticket!

This was previously discussed in #17299 and #35840, and the consensus was that we should not hide warnings caused by developer errors, unless there is a strong reason. It would just make debugging harder.

If a valid parameter generates a warning, we should certainly fix that. However, in case of an invalid parameter, I think the warning (or an error on PHP 8.0+) is to be expected.

#7 @swissspidy
20 months ago

  • Milestone Awaiting Review
  • Resolutionwontfix
  • Status newclosed

#8 @wordpressdotorg
15 months ago

  • Keywords has-test-info added; has-testing-info removed

@SergeyBiryukov commented on PR #7830:


6 months ago
#9

Thanks for the PR! Closing for now, as the associated Trac ticket has been closed.

Note: See TracTickets for help on using tickets.