#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)
Change History (17)
This ticket was mentioned in Slack in #core by ayesh. View the logs.
4 years ago
#3
@
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
@
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
Trac ticket: https://core.trac.wordpress.org/ticket/49652
This ticket was mentioned in Slack in #core-php by pbearne. View the logs.
3 years ago
hellofromtonya commented on PR #1810:
3 years ago
#14
Committed via changeset https://core.trac.wordpress.org/changeset/52039.
#15
@
3 years ago
Thank you everyone for your contributions! str_contains()
is now available for use in Core.
Here is a patch to polyfill. We can replace instances with strpos() !== false instances in core if we have this core.