[wp-trac] [WordPress Trac] #49652: Introduce new PHP cross-version compatibility functions, `str_contains()`
WordPress Trac
noreply at wordpress.org
Mon Mar 16 14:07:38 UTC 2020
#49652: Introduce new PHP cross-version compatibility functions, `str_contains()`
-----------------------------+------------------------------------------
Reporter: knutsp | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.3.2
Severity: minor | Keywords: needs-patch needs-unit-tests
Focuses: |
-----------------------------+------------------------------------------
PHP 8.0 will introduce a new function, `str_contains()`. The function
return true or false depending on the second parameter, `string $needle`,
is found in the first parameter, `string $haystack`. The RFC can be found
here https://wiki.php.net/rfc/str_contains
{{{
if ( ! function_exists( 'str_contains' ) ) {
function str_contains( string $haystack, string $needle ): bool {
return false !== strpos( $haystack, $needle );
}
}
}}}
Including a polyfill now will allow developers to take advantage of the
new function and write consistent code regardless of a site's PHP version.
Related: #45055
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49652>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list