Changeset 53365
- Timestamp:
- 05/08/2022 12:27:41 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/compat.php
r52425 r53365 9 9 // If gettext isn't available. 10 10 if ( ! function_exists( '_' ) ) { 11 function _( $ string) {12 return $ string;11 function _( $message ) { 12 return $message; 13 13 } 14 14 } … … 50 50 * @see _mb_substr() 51 51 * 52 * @param string $str 53 * @param int $start Position to being extraction from in `$str `.54 * @param int|null $length Optional. Maximum number of characters to extract from `$str `.52 * @param string $string The string to extract the substring from. 53 * @param int $start Position to being extraction from in `$string`. 54 * @param int|null $length Optional. Maximum number of characters to extract from `$string`. 55 55 * Default null. 56 56 * @param string|null $encoding Optional. Character encoding to use. Default null. 57 57 * @return string Extracted substring. 58 58 */ 59 function mb_substr( $str , $start, $length = null, $encoding = null ) {60 return _mb_substr( $str , $start, $length, $encoding );59 function mb_substr( $string, $start, $length = null, $encoding = null ) { 60 return _mb_substr( $string, $start, $length, $encoding ); 61 61 } 62 62 endif; … … 65 65 * Internal compat function to mimic mb_substr(). 66 66 * 67 * Only understands UTF-8 and 8bit. 68 * For $encoding === UTF-8, the $str input is expected to be a valid UTF-8 byte sequence.69 * The behavior of this function for invalid inputs is undefined.67 * Only understands UTF-8 and 8bit. All other character sets will be treated as 8bit. 68 * For `$encoding === UTF-8`, the `$str` input is expected to be a valid UTF-8 byte 69 * sequence. The behavior of this function for invalid inputs is undefined. 70 70 * 71 71 * @ignore … … 117 117 // Start with 1 element instead of 0 since the first thing we do is pop. 118 118 $chars = array( '' ); 119 119 120 do { 120 121 // We had some string left over from the last round, but we counted it in that last round. … … 144 145 * @see _mb_strlen() 145 146 * 146 * @param string $str 147 * @param string $string The string to retrieve the character length from. 147 148 * @param string|null $encoding Optional. Character encoding to use. Default null. 148 * @return int String length of `$str `.149 */ 150 function mb_strlen( $str , $encoding = null ) {151 return _mb_strlen( $str , $encoding );149 * @return int String length of `$string`. 150 */ 151 function mb_strlen( $string, $encoding = null ) { 152 return _mb_strlen( $string, $encoding ); 152 153 } 153 154 endif; … … 157 158 * 158 159 * Only understands UTF-8 and 8bit. All other character sets will be treated as 8bit. 159 * For $encoding === UTF-8, the `$str` input is expected to be a valid UTF-8 byte160 * For `$encoding === UTF-8`, the `$str` input is expected to be a valid UTF-8 byte 160 161 * sequence. The behavior of this function for invalid inputs is undefined. 161 162 * … … 200 201 // Start at 1 instead of 0 since the first thing we do is decrement. 201 202 $count = 1; 203 202 204 do { 203 205 // We had some string left over from the last round, but we counted it in that last round. … … 236 238 * @see _hash_hmac() 237 239 * 238 * @param string $algo 239 * @param string $data 240 * @param string $key 241 * @param bool $ raw_outputOptional. Whether to output raw binary data (true),242 * 243 * @return string|false The hash in output determined by `$ raw_output`. False if `$algo`244 * is unknown or invalid.245 */ 246 function hash_hmac( $algo, $data, $key, $ raw_output= false ) {247 return _hash_hmac( $algo, $data, $key, $ raw_output);240 * @param string $algo Hash algorithm. Accepts 'md5' or 'sha1'. 241 * @param string $data Data to be hashed. 242 * @param string $key Secret key to use for generating the hash. 243 * @param bool $binary Optional. Whether to output raw binary data (true), 244 * or lowercase hexits (false). Default false. 245 * @return string|false The hash in output determined by `$binary`. 246 * False if `$algo` is unknown or invalid. 247 */ 248 function hash_hmac( $algo, $data, $key, $binary = false ) { 249 return _hash_hmac( $algo, $data, $key, $binary ); 248 250 } 249 251 endif; … … 255 257 * @since 3.2.0 256 258 * 257 * @param string $algo 258 * @param string $data 259 * @param string $key 260 * @param bool $ raw_outputOptional. Whether to output raw binary data (true),261 * 262 * @return string|false The hash in output determined by `$ raw_output`. False if `$algo`263 * is unknown or invalid.259 * @param string $algo Hash algorithm. Accepts 'md5' or 'sha1'. 260 * @param string $data Data to be hashed. 261 * @param string $key Secret key to use for generating the hash. 262 * @param bool $binary Optional. Whether to output raw binary data (true), 263 * or lowercase hexits (false). Default false. 264 * @return string|false The hash in output determined by `$binary`. 265 * False if `$algo` is unknown or invalid. 264 266 */ 265 function _hash_hmac( $algo, $data, $key, $ raw_output= false ) {267 function _hash_hmac( $algo, $data, $key, $binary = false ) { 266 268 $packs = array( 267 269 'md5' => 'H32', … … 286 288 $hmac = $algo( $opad . pack( $pack, $algo( $ipad . $data ) ) ); 287 289 288 if ( $ raw_output) {290 if ( $binary ) { 289 291 return pack( $pack, $hmac ); 290 292 } 293 291 294 return $hmac; 292 295 } … … 294 297 if ( ! function_exists( 'hash_equals' ) ) : 295 298 /** 296 * Timing attack safe string comparison 299 * Timing attack safe string comparison. 297 300 * 298 301 * Compares two strings using the same time whether they're equal or not. … … 309 312 * @since 3.9.2 310 313 * 311 * @param string $ aExpected string.312 * @param string $ bActual, user supplied, string.314 * @param string $known_string Expected string. 315 * @param string $user_string Actual, user supplied, string. 313 316 * @return bool Whether strings are equal. 314 317 */ 315 function hash_equals( $a, $b ) { 316 $a_length = strlen( $a ); 317 if ( strlen( $b ) !== $a_length ) { 318 function hash_equals( $known_string, $user_string ) { 319 $known_string_length = strlen( $known_string ); 320 321 if ( strlen( $user_string ) !== $known_string_length ) { 318 322 return false; 319 323 } 324 320 325 $result = 0; 321 326 322 327 // Do not attempt to "optimize" this. 323 for ( $i = 0; $i < $ a_length; $i++ ) {324 $result |= ord( $ a[ $i ] ) ^ ord( $b[ $i ] );328 for ( $i = 0; $i < $known_string_length; $i++ ) { 329 $result |= ord( $known_string[ $i ] ) ^ ord( $user_string[ $i ] ); 325 330 } 326 331 … … 347 352 * @since 4.9.6 348 353 * 349 * @param mixed $va rThe value to check.350 * @return bool True if `$va r` is countable, false otherwise.351 */ 352 function is_countable( $va r) {353 return ( is_array( $va r)354 || $va rinstanceof Countable355 || $va rinstanceof SimpleXMLElement356 || $va rinstanceof ResourceBundle354 * @param mixed $value The value to check. 355 * @return bool True if `$value` is countable, false otherwise. 356 */ 357 function is_countable( $value ) { 358 return ( is_array( $value ) 359 || $value instanceof Countable 360 || $value instanceof SimpleXMLElement 361 || $value instanceof ResourceBundle 357 362 ); 358 363 } … … 368 373 * @since 4.9.6 369 374 * 370 * @param mixed $va rThe value to check.371 * @return bool True if `$va r` is iterable, false otherwise.372 */ 373 function is_iterable( $va r) {374 return ( is_array( $va r ) || $varinstanceof Traversable );375 * @param mixed $value The value to check. 376 * @return bool True if `$value` is iterable, false otherwise. 377 */ 378 function is_iterable( $value ) { 379 return ( is_array( $value ) || $value instanceof Traversable ); 375 380 } 376 381 } … … 385 390 * @since 5.9.0 386 391 * 387 * @param array $arr An array.392 * @param array $array An array. 388 393 * @return string|int|null The first key of array if the array 389 394 * is not empty; `null` otherwise. 390 395 */ 391 function array_key_first( array $arr ) {392 foreach ( $arr as $key => $value ) {396 function array_key_first( array $array ) { 397 foreach ( $array as $key => $value ) { 393 398 return $key; 394 399 } … … 405 410 * @since 5.9.0 406 411 * 407 * @param array $arr An array.412 * @param array $array An array. 408 413 * @return string|int|null The last key of array if the array 409 414 *. is not empty; `null` otherwise. 410 415 */ 411 function array_key_last( array $arr ) {412 if ( empty( $arr ) ) {416 function array_key_last( array $array ) { 417 if ( empty( $array ) ) { 413 418 return null; 414 419 } 415 end( $arr ); 416 return key( $arr ); 420 421 end( $array ); 422 423 return key( $array ); 417 424 } 418 425 } … … 453 460 return true; 454 461 } 462 455 463 return 0 === strpos( $haystack, $needle ); 456 464 } … … 474 482 return false; 475 483 } 484 476 485 $len = strlen( $needle ); 486 477 487 return 0 === substr_compare( $haystack, $needle, -$len, $len ); 478 488 }
Note: See TracChangeset
for help on using the changeset viewer.