[wp-trac] [WordPress Trac] #44123: Utilize `is_countable()` and `is_iterable()` Polyfills

WordPress Trac noreply at wordpress.org
Mon May 21 06:40:13 UTC 2018

#44123: Utilize `is_countable()` and `is_iterable()` Polyfills
 Reporter:  desrosj         |       Owner:  (none)
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  4.9.7
Component:  General         |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  close           |     Focuses:
Changes (by johnbillion):

 * keywords:  needs-patch => close


 This is an important point by @jrf.

 The `is_countable()` function should only be used before counting a value
 where it's ''valid'' for either a countable or non-countable value to be
 passed. Avoiding counting non-countable values where only countable values
 are expected will definitely introduce bugs. The same goes for
 `is_iterable()` and iterable values. See discussion on #42814 and #42860
 as examples.

 There's an inherent expectation in the hooks and filters API that the
 return values of filters are of the correct type, and core shouldn't
 silence warnings about non-iterable values being iterated, or non-
 countable values being counted, because this can mask bugs introduced by

 PHP warnings are there for a reason and are not something to be avoided at
 all costs. If a non-countable/iterable value is passed to a piece of code
 where one is expected, it is correct behaviour for a PHP warning to be

 I think this meta ticket should be closed in favour of individual tickets
 where it's been demonstrated that core is attempting to count/iterate a
 value where it's valid for that value to either be countable/iterable or
 not (which I'd hope is not very common).

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

More information about the wp-trac mailing list