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

WordPress Trac noreply at wordpress.org
Fri Sep 10 16:35:52 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-
  commit                                         |  standards
-------------------------------------------------+-------------------------

Comment (by hellofromTonya):

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

 The PHP native `mysqli_real_escape_string()` function expects to be passed
 a string as the second parameter and this is not a nullable parameter.

 Passing `null` to it will result in a `mysqli_real_escape_string():
 Passing null to parameter #2 ($string) of type string is deprecated`
 notice on PHP 8.1.

 Previously, an input type check was put in place to prevent fatal errors
 on PHP 8.0 when an array, object or resource was passed. Changeset
 [48980].

 A `null` value was explicitly excluded from that check, even though a
 `null` value being passed would only ever result in an empty string
 anyway.

 This commit changes the previous input type check to also bow out early
 for `null` values and to automatically return an empty string for those.

 Refs:
 - https://www.php.net/manual/en/mysqli.real-escape-string.php
 - https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

 Follow-up to [48980].

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

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


More information about the wp-trac mailing list