Ticket #43583: 43583.patch
| File 43583.patch, 2.4 KB (added by , 8 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_countable' ) ) { 510 /** 511 * Polyfill for is_countable function added in PHP 7.3. 512 * 513 * Verify that the content of a variable is an array or an object 514 * implementing Countable 515 * 516 * @since 4.9.6 517 * 518 * @param mixed $var The value to check. 519 * 520 * @return bool Returns true if var is countable, false otherwise. 521 */ 522 function is_countable( $var ) { 523 return ( is_array( $var ) || $var instanceof Countable ); 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 function test_is_countable_availability() { 191 $this->assertTrue( function_exists( 'is_countable' ) ); 192 } 193 194 /** 195 * Test is_countable polyfill. 196 * 197 * @ticket 43583 198 * 199 * @dataProvider countable_variable_test_data 200 */ 201 function test_is_countable_functionality($variable, $is_countable) { 202 $this->assertEquals( is_countable( $variable ), $is_countable ); 203 } 204 205 /** 206 * Data provider for test_is_countable_functionality test. First array value 207 * is the variable, and the second value is the expected return value of the 208 * PHP 7.3's is_countable function. 209 * 210 * @ticket 43583 211 * 212 * @return array test data. 213 */ 214 public function countable_variable_test_data() { 215 return array( 216 array( true, false ), 217 array( new stdClass(), false ), 218 array( new ArrayIteratorFake(), true ), 219 array( new CountableFake(), true ), 220 array( 16, false ), 221 array( null, false ), 222 array( array( 1, 2, 3 ), true ), 223 array( (array) 1, true ), 224 array( (object) array( 'foo', 'bar', 'baz' ), false ), 225 ); 226 } 189 227 } 190 228 191 229 /* used in test_mb_substr_phpcore */ … … 194 232 return 'Class A object'; 195 233 } 196 234 } 235 236 class ArrayIteratorFake extends ArrayIterator { 237 } 238 239 class CountableFake implements Countable { 240 public function count() { 241 return 16; 242 } 243 }