From d62f8581899be84fd59b987571b6c7b5d42db12e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 7 May 2023 11:42:18 +0000 Subject: [PATCH] Coding Standards: Bring more consistency to PHP 8.0 string function polyfills. This adjusts `str_contains()` code layout to have an early exit for an empty `$needle`, matching similar fragments in `str_starts_with()` and `str_ends_with()` for better readability. Follow-up to [52039], [52040]. See #57839. git-svn-id: https://develop.svn.wordpress.org/trunk@55726 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/compat.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/compat.php b/src/wp-includes/compat.php index b2017b9a08..f9df28eac9 100644 --- a/src/wp-includes/compat.php +++ b/src/wp-includes/compat.php @@ -434,11 +434,15 @@ if ( ! function_exists( 'str_contains' ) ) { * @since 5.9.0 * * @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 `$needle` is in `$haystack`, otherwise false. */ function str_contains( $haystack, $needle ) { - return ( '' === $needle || false !== strpos( $haystack, $needle ) ); + if ( '' === $needle ) { + return true; + } + + return false !== strpos( $haystack, $needle ); } }