WordPress.org

Make WordPress Core

Opened 21 months ago

Closed 3 weeks ago

Last modified 3 weeks ago

#49652 closed feature request (fixed)

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

Reported by: knutsp Owned by: hellofromTonya
Milestone: 5.9 Priority: normal
Severity: minor Version: 5.3.2
Component: General Keywords: has-patch has-unit-tests commit
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 21 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 (17)

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


19 months ago

#2 @jorbin
14 months ago

#51560 was marked as a duplicate.

#3 @desrosj
5 months ago

  • Milestone changed from Awaiting Review to 5.9
  • Owner set to desrosj
  • Status changed from new to assigned

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


4 weeks ago

This ticket was mentioned in Slack in #core-php by hellofromtonya. View the logs.


4 weeks ago

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


4 weeks ago

This ticket was mentioned in Slack in #core-php by hellofromtonya. View the logs.


4 weeks ago

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


4 weeks ago

#9 @hellofromTonya
4 weeks ago

  • Keywords has-patch added; needs-patch removed
  • Owner changed from desrosj to hellofromTonya
  • Status changed from assigned to accepted

Reassigning this ticket and other PHP polyfill tickets to me to get them into 5.9 release.

This ticket was mentioned in PR #1810 on WordPress/wordpress-develop by pbearne.


4 weeks ago

  • Keywords has-unit-tests added; needs-unit-tests removed

This ticket was mentioned in Slack in #core-php by pbearne. View the logs.


4 weeks ago

#12 @hellofromTonya
3 weeks ago

  • Keywords commit added

PR 18180 is thoroughly reviewed and ready for commit.

#13 @hellofromTonya
3 weeks ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 52039:

General: Introduce polyfill for str_contains() added in PHP 8.0.

PHP 8.0 introduced a new function: str_contains(). It performs a case-sensitive check indicating if given substring (needle) is contained in the string to search in (haystack).

This polyfill makes this function available for use in Core.

Ref:

Props ayeshrajans, costdev, desrosj, hellofromTonya, knutsp, pbearne.
Fixes #49652.

#15 @hellofromTonya
3 weeks ago

Thank you everyone for your contributions! str_contains() is now available for use in Core.

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


3 weeks ago

Note: See TracTickets for help on using tickets.