WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 5 weeks ago

#49652 assigned feature request

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

Reported by: knutsp Owned by: desrosj
Milestone: 5.9 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 17 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 (4)

@ayeshrajans
17 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.


15 months ago

#2 @jorbin
10 months ago

#51560 was marked as a duplicate.

#3 @desrosj
5 weeks ago

  • Milestone changed from Awaiting Review to 5.9
  • Owner set to desrosj
  • Status changed from new to assigned
Note: See TracTickets for help on using tickets.