WordPress.org

Make WordPress Core

Opened 4 hours ago

#49652 new feature request

Introduce new PHP cross-version compatibility functions, `str_contains()`

Reported by: knutsp Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.3.2
Component: General Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

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

Change History (0)

Note: See TracTickets for help on using tickets.