diff --git src/wp-includes/compat.php src/wp-includes/compat.php
index 7377a384c8..83221c74fc 100644
|
|
|
endif;
|
| 505 | 505 | if ( ! function_exists( 'spl_autoload_register' ) ) { |
| 506 | 506 | require_once ABSPATH . WPINC . '/spl-autoload-compat.php'; |
| 507 | 507 | } |
| | 508 | |
| | 509 | if ( ! function_exists( 'is_iterable' ) ) { |
| | 510 | /** |
| | 511 | * Polyfill for is_iterable function added in PHP 7.1. |
| | 512 | * |
| | 513 | * Verify that the content of a variable is a non-empty array or an object |
| | 514 | * implementing the Traversable interface. |
| | 515 | * |
| | 516 | * @since 5.0 |
| | 517 | * |
| | 518 | * @param mixed $var Variable to check. |
| | 519 | * |
| | 520 | * @return bool Whether the provided variable is iterable. |
| | 521 | */ |
| | 522 | function is_iterable( $var ) { |
| | 523 | return ( is_array( $var ) && ! empty( $var ) ) |
| | 524 | || $var instanceof Traversable; |
| | 525 | } |
| | 526 | } |
diff --git tests/phpunit/tests/compat.php tests/phpunit/tests/compat.php
index 3d873745b9..1dd0c925d4 100644
|
|
|
EOT;
|
| 186 | 186 | $this->assertEquals( '["foo"]', $json->encodeUnsafe( array( 'foo' ) ) ); |
| 187 | 187 | $this->assertEquals( array( 'foo' ), $json->decode( '["foo"]' ) ); |
| 188 | 188 | } |
| | 189 | |
| | 190 | /** |
| | 191 | * @dataProvider iterable_variable_test_data |
| | 192 | * @param mixed $variable |
| | 193 | * @param bool $expected |
| | 194 | */ |
| | 195 | function test_is_iterable( $variable, $expected ) { |
| | 196 | $this->assertEquals( is_iterable( $variable ), $expected ); |
| | 197 | } |
| | 198 | |
| | 199 | function iterable_variable_test_data() { |
| | 200 | return array( |
| | 201 | array( array( 1, 2, 3 ), true ), |
| | 202 | array( new \ArrayIterator( array( 1, 2, 3 ) ), true ), |
| | 203 | array( 1, false ), |
| | 204 | array( 3.14, false ), |
| | 205 | array( new stdClass(), false ), |
| | 206 | ); |
| | 207 | } |
| 189 | 208 | } |
| 190 | 209 | |
| 191 | 210 | /* used in test_mb_substr_phpcore */ |