[wp-trac] [WordPress Trac] #58220: Replace usage of substr with str_starts_with and str_ends_with

WordPress Trac noreply at wordpress.org
Fri Apr 28 10:33:21 UTC 2023


#58220: Replace usage of substr with str_starts_with and str_ends_with
--------------------------+-----------------------------
 Reporter:  Soean         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 Replace `$needle === substr( $string, 0, $length )` with `str_starts_with(
 $haystack, $needle )`. `$length` should be the length of `$needle`.

 Replace `$needle === substr($string, $offset)` where `$offset` is negative
 with `str_ends_with( $haystack, $needle )`. The absolute value of
 `$offset` should be the length of `$needle`.

 It makes the code more readable and use a PHP native function ( which may
 have a performance benefit ).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58220>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list