Make WordPress Core


Ignore:
Timestamp:
04/30/2018 04:16:43 AM (8 years ago)
Author:
SergeyBiryukov
Message:

General: Introduce a polyfill for is_iterable() function added in PHP 7.1.

Props jrf, schlessera, desrosj.
Merges [43036] to the 4.9 branch.
See #43619.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/compat.php

    r43035 r43037  
    504504         *
    505505         * Verify that the content of a variable is an array or an object
    506          * implementing Countable.
     506         * implementing the Countable interface.
    507507         *
    508508         * @since 4.9.6
     
    516516        }
    517517}
     518
     519if ( ! function_exists( 'is_iterable' ) ) {
     520        /**
     521         * Polyfill for is_iterable() function added in PHP 7.1.
     522         *
     523         * Verify that the content of a variable is an array or an object
     524         * implementing the Traversable interface.
     525         *
     526         * @since 4.9.6
     527         *
     528         * @param mixed $var The value to check.
     529         *
     530         * @return bool True if `$var` is iterable, false otherwise.
     531         */
     532        function is_iterable( $var ) {
     533                return ( is_array( $var ) || $var instanceof Traversable );
     534        }
     535}
Note: See TracChangeset for help on using the changeset viewer.