[wp-trac] [WordPress Trac] #58012: Replace usage of strpos with str_starts_with

WordPress Trac noreply at wordpress.org
Wed Mar 29 14:18:39 UTC 2023


#58012: Replace usage of strpos with str_starts_with
----------------------------------------+------------------------------
 Reporter:  spacedmonkey                |       Owner:  (none)
     Type:  enhancement                 |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  General                     |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  needs-patch good-first-bug  |     Focuses:
----------------------------------------+------------------------------

Comment (by desrosj):

 Just a few notes to provide full context.

 The `str_starts_with()` function is only available on PHP 8.0+. The
 function was polyfilled into Core in 5.9 along with `str_ends_with()` in
 [52040], so we can safely update the codebase, but it's likely sites
 running PHP 5.x & 7.x won't see the likely performance improvement sites
 using 8.x will.

 `str_contains()` was also polyfilled in [52039].

 Seems there was an adhoc instances of these new functions being added in
 [52326], but seems that was the only case where this was intentionally
 updated.

 I think this is a good change to make provided we have tests in all the
 right places. It also seems like a reasonable assumption that sites
 running PHP 8.0+ would see some form of a performance increase, but would
 be great to have some benchmarking to know the real impact of this change.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58012#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list