[wp-trac] [WordPress Trac] #53635: PHP 8.1: various compatibility fixes

WordPress Trac noreply at wordpress.org
Wed Sep 22 23:33:38 UTC 2021


#53635: PHP 8.1: various compatibility fixes
--------------------------------------------+------------------------------
 Reporter:  SergeyBiryukov                  |       Owner:  hellofromTonya
     Type:  task (blessed)                  |      Status:  accepted
 Priority:  normal                          |   Milestone:  5.9
Component:  General                         |     Version:
 Severity:  normal                          |  Resolution:
 Keywords:  php81 has-patch has-unit-tests  |     Focuses:  coding-
                                            |  standards
--------------------------------------------+------------------------------

Comment (by hellofromTonya):

 In [changeset:"51853" 51853]:
 {{{
 #!CommitTicketReference repository="" revision="51853"
 Code Modernization: Fix "passing null to non-nullable" deprecation in
 `_mb_substr()`.

 The `_mb_substr()` function expects a string for the `$str` parameter, but
 does not do input validation. This function contains a `preg_match_all()`
 which also expects a string type for the given subject (i.e. `$str`).

 Passing `null` to this parameter results in `preg_match_all(): Passing
 null to parameter #2 ($subject) of type string is deprecated` notice on
 PHP 8.1.

 To maintain the same behaviour as before, a guard clause is added to bail
 out early when `$str` is passed as `null`. The outcome will, in that case,
 only ever be an empty string.

 Note: this does mean that the `_mb_substr()` function now has a subtle
 difference in behaviour compared to the PHP native `mb_substr()` function
 as the latter ''will'' throw the deprecation notice.

 The existing tests already cover this issue.

 Follow-up to [17621], [36017], [32364].

 Props jrf, hellofromTonya.
 See #53635.
 }}}

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


More information about the wp-trac mailing list