Skip to content

Commit d62f858

Browse files
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
1 parent 24c4d56 commit d62f858

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/wp-includes/compat.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,15 @@ function array_key_last( array $array ) { // phpcs:ignore Universal.NamingConven
434434
* @since 5.9.0
435435
*
436436
* @param string $haystack The string to search in.
437-
* @param string $needle The substring to search for in the haystack.
437+
* @param string $needle The substring to search for in the `$haystack`.
438438
* @return bool True if `$needle` is in `$haystack`, otherwise false.
439439
*/
440440
function str_contains( $haystack, $needle ) {
441-
return ( '' === $needle || false !== strpos( $haystack, $needle ) );
441+
if ( '' === $needle ) {
442+
return true;
443+
}
444+
445+
return false !== strpos( $haystack, $needle );
442446
}
443447
}
444448

0 commit comments

Comments
 (0)