[wp-trac] [WordPress Trac] #46346: WP_List_Table calculates total_pages as a float

WordPress Trac noreply at wordpress.org
Wed Jan 27 00:39:43 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):

 @jrf I don't understand the attitude over such a trivial fix, and that's
 thrice now you've not actually read this thread (first a missed patch,
 then missed [comment:5 the actual problem], then suggested a fix that was
 already explicitly reasoned against). I'm sure you're a busy person but
 not fully engaging is wasting your time, too.

 The problem is that the type does not compare to integers as expected,
 which is how I discovered the bug. I wrote a class that extends
 `WP_List_Table`, as have many, many coders before me. In my class, I
 compared page totals with an integer setting, and got odd behaviour
 because they were floats. I worked around the issue by overriding the
 `set_pagination_args()` method and passing a correct value to the parent
 method.

 As previously stated, the existing type is okay for display but not for
 extensibility.

 > Oh and as I said before, if you want to actually eliminate the
 possibility that this problem would, for some future iteration of this
 code, crop up - your patches do not safeguard this.
 >
 > In that case, the code would need to switch to using BCMath.

 How so? Do you mean if `total_items` and `per_page` are not integers? If
 so, when would they not be? Or do you mean if those values aren't <=
 `PHP_INT_MAX`? This patch is not intended to guard against bad input (and
 nor does the current version), but rather to produce better ''output''. It
 also eliminates the overhead of a function call and introduces no new
 dependencies. Is WordPress planning on using BCMath here? If not, why
 suggest it?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46346#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list