General: Fix nesting in compat.php.

Follow up to [57451].

Built from https://develop.svn.wordpress.org/branches/5.7@57456


git-svn-id: http://core.svn.wordpress.org/branches/5.7@56957 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Joe McGill 2024-01-30 18:16:03 +00:00
parent b584f790fc
commit f51ef1dabe
1 changed files with 42 additions and 42 deletions

View File

@ -369,50 +369,50 @@ if ( ! function_exists( 'is_iterable' ) ) {
function is_iterable( $var ) { function is_iterable( $var ) {
return ( is_array( $var ) || $var instanceof Traversable ); return ( is_array( $var ) || $var instanceof Traversable );
} }
}
if ( ! function_exists( 'str_starts_with' ) ) { if ( ! function_exists( 'str_starts_with' ) ) {
/** /**
* Polyfill for `str_starts_with()` function added in PHP 8.0. * Polyfill for `str_starts_with()` function added in PHP 8.0.
* *
* Performs a case-sensitive check indicating if * Performs a case-sensitive check indicating if
* the haystack begins with needle. * the haystack begins with needle.
* *
* @since 5.9.0 * @since 5.9.0
* *
* @param string $haystack The string to search in. * @param string $haystack The string to search in.
* @param string $needle The substring to search for in the `$haystack`. * @param string $needle The substring to search for in the `$haystack`.
* @return bool True if `$haystack` starts with `$needle`, otherwise false. * @return bool True if `$haystack` starts with `$needle`, otherwise false.
*/ */
function str_starts_with( $haystack, $needle ) { function str_starts_with( $haystack, $needle ) {
if ( '' === $needle ) { if ( '' === $needle ) {
return true; return true;
}
return 0 === strpos( $haystack, $needle );
} }
}
if ( ! function_exists( 'str_ends_with' ) ) { return 0 === strpos( $haystack, $needle );
/** }
* Polyfill for `str_ends_with()` function added in PHP 8.0. }
*
* Performs a case-sensitive check indicating if if ( ! function_exists( 'str_ends_with' ) ) {
* the haystack ends with needle. /**
* * Polyfill for `str_ends_with()` function added in PHP 8.0.
* @since 5.9.0 *
* * Performs a case-sensitive check indicating if
* @param string $haystack The string to search in. * the haystack ends with needle.
* @param string $needle The substring to search for in the `$haystack`. *
* @return bool True if `$haystack` ends with `$needle`, otherwise false. * @since 5.9.0
*/ *
function str_ends_with( $haystack, $needle ) { * @param string $haystack The string to search in.
if ( '' === $haystack ) { * @param string $needle The substring to search for in the `$haystack`.
return '' === $needle; * @return bool True if `$haystack` ends with `$needle`, otherwise false.
} */
function str_ends_with( $haystack, $needle ) {
$len = strlen( $needle ); if ( '' === $haystack ) {
return '' === $needle;
return substr( $haystack, -$len, $len ) === $needle; }
}
$len = strlen( $needle );
return substr( $haystack, -$len, $len ) === $needle;
} }
} }