[wp-trac] [WordPress Trac] #58206: Replace usage of strpos with str_contains
WordPress Trac
noreply at wordpress.org
Thu Apr 27 12:44:30 UTC 2023
#58206: Replace usage of strpos with str_contains
----------------------------+--------------------------------------------
Reporter: spacedmonkey | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.3
Component: General | Version:
Severity: normal | Resolution:
Keywords: good-first-bug | Focuses: performance, coding-standards
----------------------------+--------------------------------------------
Changes (by SergeyBiryukov):
* milestone: Awaiting Review => 6.3
Old description:
> Replace usage of false === strpos or false !== strpos with
> str_starts_with. It makes the code more readable and use a PHP native
> function ( which may have a performance benefit ).
>
> Follow on from #58012
New description:
Replace usage of `false === strpos` or `false !== strpos` with
`str_contains`. It makes the code more readable and use a PHP native
function ( which may have a performance benefit ).
Follow on from #58012.
--
Comment:
Replying to [comment:2 dingo_d]:
> `str_starts_with` is PHP 8+ syntax, so you cannot just replace `strpos`
checks with it until the minimum PHP version is raised to PHP 8 if I'm not
mistaken...
WordPress core includes a polyfill for `str_contains()` as of [52039] /
#49652, as well as `str_starts_with()` and `str_ends_with()` as of [52040]
/ #54377, so the change should be safe to make, see the discussion in
#58012.
This ticket is about `str_contains()` though, updating the description to
avoid confusion.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58206#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list