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

WordPress Trac noreply at wordpress.org
Wed May 3 21:35:12 UTC 2023


#58012: Replace usage of strpos with str_starts_with
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:
                                                 |  SergeyBiryukov
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.3
Component:  General                              |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch 2nd-        |     Focuses:
  opinion                                        |
-------------------------------------------------+-------------------------

Comment (by SergeyBiryukov):

 Replying to [comment:40 flixos90]:
 > this is about code patterns, like following the latest available PHP
 best practices.

 Yeah, that's how I see this ticket too. We already use `str_starts_with()`
 in a few places in core (a bit randomly), so might as well do that in a
 consistent way to improve code quality.

 While `strpos()` has to search the entire string, `str_starts_with()` is
 optimized for the particular use case of only checking the beginning, so
 in the long run in will be a minor performance improvement as well.

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


More information about the wp-trac mailing list