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

WordPress Trac noreply at wordpress.org
Wed Mar 29 22:12:03 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 SergeyBiryukov):

 Replying to [comment:1 spacedmonkey]:
 > @SergeyBiryukov This is a code quality thing, I would love your thoughts
 on this.

 Looks like I had some thoughts earlier in comment:8:ticket:56791 (thanks
 @TobiasBg!):
 > I am in favor of making a batch replacement to use `str_contains()`,
 `str_starts_with()`, and `str_ends_with()` where appropriate, for
 readability and consistency.

 Replying to [comment:4 jorbin]:
 > I ran a quick test - https://3v4l.org/dUbZ9 which shows that strpos is
 slightly faster before PHP8

 Thanks for the test! True, but it also appears to show that
 `str_starts_with()` is twice as fast on PHP 8.0+. As we gradually move to
 modern PHP versions, this seems like a small but beneficial performance
 improvement.

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


More information about the wp-trac mailing list