WordPress.org

Make WordPress Core


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

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

Props jrf, ayeshrajans, desrosj.
Merges [43034] to the 4.9 branch.
See #43583.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

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

    r41178 r43035  
    498498    require_once ABSPATH . WPINC . '/spl-autoload-compat.php';
    499499}
     500
     501if ( ! function_exists( 'is_countable' ) ) {
     502    /**
     503     * Polyfill for is_countable() function added in PHP 7.3.
     504     *
     505     * Verify that the content of a variable is an array or an object
     506     * implementing Countable.
     507     *
     508     * @since 4.9.6
     509     *
     510     * @param mixed $var The value to check.
     511     *
     512     * @return bool True if `$var` is countable, false otherwise.
     513     */
     514    function is_countable( $var ) {
     515        return ( is_array( $var ) || $var instanceof Countable );
     516    }
     517}
Note: See TracChangeset for help on using the changeset viewer.