Ticket #43619: 43619.3.diff
File 43619.3.diff, 1.8 KB (added by , 6 years ago) |
---|
-
src/wp-includes/compat.php
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 4.9.6 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 ) || $var instanceof Traversable ); 524 } 525 } -
tests/phpunit/tests/compat.php
186 186 $this->assertEquals( '["foo"]', $json->encodeUnsafe( array( 'foo' ) ) ); 187 187 $this->assertEquals( array( 'foo' ), $json->decode( '["foo"]' ) ); 188 188 } 189 190 /** 191 * @ticket 43619 192 * @dataProvider iterable_variable_test_data 193 * @param mixed $variable 194 * @param bool $expected 195 */ 196 function test_is_iterable( $variable, $expected ) { 197 $this->assertEquals( is_iterable( $variable ), $expected ); 198 } 199 200 /** 201 * @ticket 43619 202 */ 203 function iterable_variable_test_data() { 204 return array( 205 array( array(), true ), 206 array( array( 1, 2, 3 ), true ), 207 array( new \ArrayIterator( array( 1, 2, 3 ) ), true ), 208 array( 1, false ), 209 array( 3.14, false ), 210 array( new stdClass(), false ), 211 ); 212 } 189 213 } 190 214 191 215 /* used in test_mb_substr_phpcore */