[wp-trac] [WordPress Trac] #43619: Introduce new PHP cross-version compat function `is_iterable()`

WordPress Trac noreply at wordpress.org
Fri Apr 20 16:24:45 UTC 2018


#43619: Introduce new PHP cross-version compat function `is_iterable()`
--------------------------------------+---------------------
 Reporter:  jrf                       |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  4.9.6
Component:  General                   |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------
Changes (by jrf):

 * keywords:  has-patch has-unit-tests commit => has-patch has-unit-tests


Comment:

 I think we still need one more change here - mea culpa.

 When I created the ticket I did something (not so) "clever". I added `&& !
 empty( $var )` to the conditional in the function
 {{{#!php
 <?php
 return ( ( is_array( $var ) && ! empty( $var ) || $var instanceof
 Traversable );
 }}}

 However, the PHP native function does not do such a check, so as it
 stands, there will be situations where the WP back-fill does not give the
 same result as the PHP native function which is undesirable and will be
 the cause of bugs in the long run (once PHP 7.3 has come out).

 Sorry about that.

 The latest patch does contain the `&& ! empty( $var )`, so it will need to
 be removed and if no unit tests are failing after that, we need to add a
 unit test for an empty array.

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


More information about the wp-trac mailing list