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

WordPress Trac noreply at wordpress.org
Tue May 2 19:26:31 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 changes-         |  standards
  requested                          |
-------------------------------------+-------------------------------------
Changes (by azaozz):

 * keywords:  good-first-bug has-patch => good-first-bug has-patch 2nd-
     opinion changes-requested


Comment:

 I have "mixed feelings" about this. Imho replacing `false === strpos( ...
 )` and `false !== strpos( ... )` with `str_contains()` is premature.

 The problem is that only ~20% of the current WP sites are on PHP 8+. So
 80% will have to use the polyfill. Then the question is: is that polyfill
 faster than the native PHP 7.4 code? I did a quick comparison and it seems
 about 280% slower:

 {{{
 2.350807ms
 false !== strpos(), 100000 times

 7.260107ms
 str_contains(), 100000 times
 }}}

 So it seems this should be postponed until (at least) more than half of
 the WP installs are on PHP 8+ as it reduces performance.

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


More information about the wp-trac mailing list