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

WordPress Trac noreply at wordpress.org
Mon Sep 20 18:49:00 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:"51830" 51830]:
 {{{
 #!CommitTicketReference repository="" revision="51830"
 REST API: Fix autovivification deprecation notice in
 `WP_Test_REST_Widgets_Controller::set_up()`.

 If the `'widget_testwidget'` option does not exist, `false` was returned
 from `get_option()`. The `set_up()` logic expects an `array()` and assigns
 values to keys without checking for an array. The automatic creation of an
 array (autovivification) triggers a `Deprecated: Automatic conversion of
 false to array is deprecated in` deprecation notice on PHP 8.1.

 This commit:
 - Fixes the deprecation notice by making the default value an empty array.
 - Moves getting the option within the conditional where it's needed.
 - Provides a micro-optimization by only getting the options when the
 conditions are correct for processing.
 - Makes the code consistent within the `set_up()` for both `get_option()`
 instances.

 Follow-up to [51029].

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

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


More information about the wp-trac mailing list