Make WordPress Core


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

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

Props jrf, schlessera, desrosj.
See #43619.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/compat.php

    r43034 r43036  
    512512         *
    513513         * Verify that the content of a variable is an array or an object
    514          * implementing Countable.
     514         * implementing the Countable interface.
    515515         *
    516516         * @since 4.9.6
     
    524524        }
    525525}
     526
     527if ( ! function_exists( 'is_iterable' ) ) {
     528        /**
     529         * Polyfill for is_iterable() function added in PHP 7.1.
     530         *
     531         * Verify that the content of a variable is an array or an object
     532         * implementing the Traversable interface.
     533         *
     534         * @since 4.9.6
     535         *
     536         * @param mixed $var The value to check.
     537         *
     538         * @return bool True if `$var` is iterable, false otherwise.
     539         */
     540        function is_iterable( $var ) {
     541                return ( is_array( $var ) || $var instanceof Traversable );
     542        }
     543}
Note: See TracChangeset for help on using the changeset viewer.