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

WordPress Trac noreply at wordpress.org
Wed May 3 12:40:43 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                                        |  performance
-------------------------------------------------+-------------------------

Comment (by spacedmonkey):

 script-loader.php Seems to have used since [55658]. Before this commit.
 This file needs those compatibility functions.

 Regarding performance on PHP 8.0+ is a little bit faster. AS for PHP 8.0-,
 the compablity shim from str_starts_with has a check for if the needle is,
 meaning `0 === strpos()` is not exactly the same as `str_starts_with`.
 Having error handling on needle is a code quality thing IMO.

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


More information about the wp-trac mailing list