[wp-trac] [WordPress Trac] #46346: WP_List_Table calculates total_pages as a float
WordPress Trac
noreply at wordpress.org
Tue Jan 26 21:02:37 UTC 2021
#46346: WP_List_Table calculates total_pages as a float
----------------------------+-----------------------------
Reporter: lev0 | Owner: SergeyBiryukov
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 5.7
Component: Administration | Version:
Severity: minor | Resolution:
Keywords: has-patch | Focuses:
----------------------------+-----------------------------
Comment (by lev0):
Replying to [comment:7 jrf]:
> I've reviewed the patch and am not a fan.
The corrected patch is in comment:3
> Otherwise, an alternative solution would be:
> {{{#!php
> <?php
> $args['total_pages'] = (int) round( ceil( $args['total_items'] /
$args['per_page'] ), 0); // Using round to prevent floating point issues.
> }}}
Please no. This is exactly problem, both are functions that return floats
where people expect ints, and are still vulnerable to integer truncation.
Also, the `round()` does nothing except waste cycles because `ceil()` has
already found the float value nearest to the expected int.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46346#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list