Make WordPress Core

Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#49652 closed feature request (fixed)

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

Reported by: knutsp Owned by: hellofromTonya
Priority: normal Milestone: 5.9
Component: General Version: 5.3.2
Severity: minor Keywords: has-patch has-unit-tests commit
Cc: Focuses:

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 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
7 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.


6 years ago

#2 @jorbin
6 years ago

#51560 was marked as a duplicate.

#3 @desrosj
5 years ago

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

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


5 years ago

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


5 years ago

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


5 years ago

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


5 years ago

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


5 years ago

#9 @hellofromTonya
5 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner changed from desrosj to hellofromTonya
  • Status assigned → 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.


5 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.


5 years ago

#12 @hellofromTonya
5 years ago

  • Keywords commit added

PR 18180 is thoroughly reviewed and ready for commit.

#13 @hellofromTonya
5 years ago

  • Resolution → fixed
  • Status accepted → 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
5 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.


5 years ago

Note: See TracTickets for help on using tickets.