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

WordPress Trac noreply at wordpress.org
Mon Aug 16 22:16:49 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 SergeyBiryukov):

 In [changeset:"51624" 51624]:
 {{{
 #!CommitTicketReference repository="" revision="51624"
 Code Modernization: Correct handling of `null` in `wp_parse_str()`.

 This fixes `parse_str(): Passing null to parameter #1 ($string) of type
 string is deprecated` notices on PHP 8.1, without change in behaviour.

 Impact: 311 of the pre-existing tests are affected by this issue.

 The PHP native `parse_str()` function expects a string, however, based on
 the failing tests, it is clear there are functions in WordPress which
 passes a non-string – including `null` – value to the `wp_parse_str()`
 function, which would subsequently pass it onto the PHP native function
 without further input validation.

 Most notable offender is the `wp_parse_args()` function which special
 cases arrays and objects, but passes everything else off to
 `wp_parse_str()`.

 Several ways to fix this issue have been explored, including checking the
 received value with `is_string()` or `is_scalar()` before passing it off
 to the PHP native `parse_str()` function.

 In the end it was decided against these in favor of a string cast as:
 * `is_string()` would significantly change the behavior for anything non-
 string.
 * `is_scalar()` up to a point as well, as it does not take objects with a
 `__toString()` method into account.

 Executing a string cast on the received value before passing it on
 maintains the pre-existing behavior while still preventing the deprecation
 notice coming from PHP 8.1.

 Reference: [https://www.php.net/manual/en/function.parse-str.php PHP
 Manual: parse_str()]

 Follow-up to [5709].

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

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


More information about the wp-trac mailing list