Make WordPress Core

Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#49652 closed feature request (fixed)

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

Reported by: knutsp's profile knutsp Owned by: hellofromtonya's profile 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 5 years 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
5 years 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.


4 years ago

#2 @jorbin
4 years ago

#51560 was marked as a duplicate.

#3 @desrosj
3 years 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.


3 years ago

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


3 years ago

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


3 years ago

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


3 years ago

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


3 years ago

#9 @hellofromTonya
3 years 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.


3 years ago
#10

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

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


3 years ago

#12 @hellofromTonya
3 years ago

  • Keywords commit added

PR 18180 is thoroughly reviewed and ready for commit.

#13 @hellofromTonya
3 years 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 years 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 years ago

Note: See TracTickets for help on using tickets.