WordPress.org

Make WordPress Core

Ticket #43583: is_countable-polyfill-43583.patch

File is_countable-polyfill-43583.patch, 828 bytes (added by ayeshrajans, 4 years ago)

Pretty straight forward, so I did a try. Function signature and docblock is based on the RFC's example.

  • src/wp-includes/compat.php

    diff --git a/src/wp-includes/compat.php b/src/wp-includes/compat.php
    index 7377a384c8..2cd63aef3e 100644
    a b function array_replace_recursive( $base = array(), $replacements = array() ) { 
    505505if ( ! function_exists( 'spl_autoload_register' ) ) {
    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         * Verify that the content of a variable is an array or an object
     513         * implementing Countable
     514         *
     515         * @param mixed $var The value to check.
     516         * @return bool Returns TRUE if var is countable, FALSE otherwise.
     517         */
     518        function is_countable( $var ) {
     519                return ( is_array( $var ) || $var instanceof Countable );
     520        }
     521endif;