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

Props jrf, schlessera, desrosj.
See #43619.

git-svn-id: https://develop.svn.wordpress.org/trunk@43036 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2018-04-30 04:14:30 +00:00
parent 8edb00171c
commit 451ba4c401
2 changed files with 60 additions and 1 deletions

View File

@@ -511,7 +511,7 @@ if ( ! function_exists( 'is_countable' ) ) {
* Polyfill for is_countable() function added in PHP 7.3.
*
* Verify that the content of a variable is an array or an object
* implementing Countable.
* implementing the Countable interface.
*
* @since 4.9.6
*
@@ -523,3 +523,21 @@ if ( ! function_exists( 'is_countable' ) ) {
return ( is_array( $var ) || $var instanceof Countable );
}
}
if ( ! function_exists( 'is_iterable' ) ) {
/**
* Polyfill for is_iterable() function added in PHP 7.1.
*
* Verify that the content of a variable is an array or an object
* implementing the Traversable interface.
*
* @since 4.9.6
*
* @param mixed $var The value to check.
*
* @return bool True if `$var` is iterable, false otherwise.
*/
function is_iterable( $var ) {
return ( is_array( $var ) || $var instanceof Traversable );
}
}