[wp-trac] [WordPress Trac] #58206: Replace usage of strpos with str_contains

WordPress Trac noreply at wordpress.org
Wed Jun 14 09:12:32 UTC 2023


#58206: Replace usage of strpos with str_contains
-------------------------------------+-------------------------------------
 Reporter:  spacedmonkey             |       Owner:  SergeyBiryukov
     Type:  enhancement              |      Status:  assigned
 Priority:  normal                   |   Milestone:  6.3
Component:  General                  |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  good-first-bug has-      |     Focuses:  performance, coding-
  patch 2nd-opinion commit           |  standards
-------------------------------------+-------------------------------------

Comment (by spacedmonkey):

 @azaozz Can you provide more information on how you got these numbers.
 What software or tool was used to generate these numbers? What versions of
 PHP were used, was opcache enabled?

 The process I used to benchmark the PR is documented
 [https://make.wordpress.org/performance/handbook/measuring-performance
 /benchmarking-php-performance-with-server-timing/ here]. I have run both
 benchmark and profiles on this change and seen positive results.

 It worth noting that `str_contains` and `false === strpos( ... )` are not
 exactly the same. The compatibility shim, in compat.php, does `false ===
 strpos( ... )` but also does a check to see if the `$needle` is an empty
 string. This is a little extra logic. That said, I see this as a positive
 as it hardens the code with better checks.

 I think this change should be committed.

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


More information about the wp-trac mailing list