Changeset 43036
- Timestamp:
- 04/30/2018 04:14:30 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/compat.php
r43034 r43036 512 512 * 513 513 * Verify that the content of a variable is an array or an object 514 * implementing Countable.514 * implementing the Countable interface. 515 515 * 516 516 * @since 4.9.6 … … 524 524 } 525 525 } 526 527 if ( ! function_exists( 'is_iterable' ) ) { 528 /** 529 * Polyfill for is_iterable() function added in PHP 7.1. 530 * 531 * Verify that the content of a variable is an array or an object 532 * implementing the Traversable interface. 533 * 534 * @since 4.9.6 535 * 536 * @param mixed $var The value to check. 537 * 538 * @return bool True if `$var` is iterable, false otherwise. 539 */ 540 function is_iterable( $var ) { 541 return ( is_array( $var ) || $var instanceof Traversable ); 542 } 543 } -
trunk/tests/phpunit/tests/compat.php
r43034 r43036 231 231 ); 232 232 } 233 234 /** 235 * @ticket 43619 236 */ 237 function test_is_iterable_availability() { 238 $this->assertTrue( function_exists( 'is_iterable' ) ); 239 } 240 241 /** 242 * Test is_iterable() polyfill. 243 * 244 * @ticket 43619 245 * 246 * @dataProvider iterable_variable_test_data 247 */ 248 function test_is_iterable_functionality( $variable, $is_iterable ) { 249 $this->assertEquals( is_iterable( $variable ), $is_iterable ); 250 } 251 252 /** 253 * Data provider for test_is_iterable_functionality(). 254 * 255 * @ticket 43619 256 * 257 * @return array { 258 * @type array { 259 * @type mixed $variable Variable to check. 260 * @type bool $is_iterable The expected return value of PHP 7.1 is_iterable() function. 261 * } 262 * } 263 */ 264 public function iterable_variable_test_data() { 265 return array( 266 array( array(), true ), 267 array( array( 1, 2, 3 ), true ), 268 array( new ArrayIterator( array( 1, 2, 3 ) ), true ), 269 array( 1, false ), 270 array( 3.14, false ), 271 array( new stdClass(), false ), 272 ); 273 } 233 274 } 234 275
Note: See TracChangeset
for help on using the changeset viewer.