WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 7 days 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

Attachments (1)

49652-1.patch (463 bytes) - added by ayeshrajans 7 months ago.
Here is a patch to polyfill. We can replace instances with strpos() !== false instances in core if we have this core.

Download all attachments as: .zip

Change History (3)

@ayeshrajans
7 months ago

Here is a patch to polyfill. We can replace instances with strpos() !== false instances in core if we have this core.

This ticket was mentioned in Slack in #core by ayesh. View the logs.


6 months ago

#2 @jorbin
7 days ago

#51560 was marked as a duplicate.

Note: See TracTickets for help on using tickets.