mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user