Make WordPress Core


Ignore:
Timestamp:
04/30/2018 03:42:46 AM (7 years ago)
Author:
SergeyBiryukov
Message:

General: Introduce a polyfill for is_countable() function added in PHP 7.3.

Props jrf, ayeshrajans, desrosj.
See #43583.

File:
1 edited

Legend:

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

    r42343 r43034  
    506506    require_once ABSPATH . WPINC . '/spl-autoload-compat.php';
    507507}
     508
     509if ( ! function_exists( 'is_countable' ) ) {
     510    /**
     511     * Polyfill for is_countable() function added in PHP 7.3.
     512     *
     513     * Verify that the content of a variable is an array or an object
     514     * implementing Countable.
     515     *
     516     * @since 4.9.6
     517     *
     518     * @param mixed $var The value to check.
     519     *
     520     * @return bool True if `$var` is countable, false otherwise.
     521     */
     522    function is_countable( $var ) {
     523        return ( is_array( $var ) || $var instanceof Countable );
     524    }
     525}
Note: See TracChangeset for help on using the changeset viewer.