[wp-trac] [WordPress Trac] #46346: WP_List_Table calculates total_pages as a float
WordPress Trac
noreply at wordpress.org
Mon Jan 25 22:13:27 UTC 2021
#46346: WP_List_Table calculates total_pages as a float
----------------------------+------------------------------
Reporter: lev0 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version:
Severity: minor | Resolution:
Keywords: has-patch | Focuses:
----------------------------+------------------------------
Comment (by lev0):
I understand `ceil()` function, and I also understand how floating point
numbers work.
1. It's possible if someone uses an arbitrary number for `$per_page` with
this class.
2. No, see [https://www.php.net/manual/en/language.types.integer.php the
warning under the "From floating point numbers" heading] about casting to
integers. `ceil()` returns a float, which may be fine for ''display''
(because PHP assumes you want an `8` when you output a variable that
contains `7.9999999999999991118`), but not for ''numeric comparisons''.
Casting a number like `23.999999999999999999999…` to an int gives `23`,
not `24`, which is worse than just leaving it as the float.
The number will always be as close as possible to the integer when not
exact, but it's still not exact. The ethos of WordPress includes
extensibility, so why knowingly give data that **can** cause edge cases?
Arguing for retaining an error-prone float calc is very reminiscent of the
Bad Old Days™ of PHP.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46346#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list