[wp-trac] [WordPress Trac] #50913: PHP 8.0: various compatibility fixes

WordPress Trac noreply at wordpress.org
Fri Aug 21 21:49:17 UTC 2020


#50913: PHP 8.0: various compatibility fixes
----------------------------+-------------------------------
 Reporter:  jrf             |       Owner:  SergeyBiryukov
     Type:  task (blessed)  |      Status:  reviewing
 Priority:  normal          |   Milestone:  5.6
Component:  General         |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  php8 has-patch  |     Focuses:  coding-standards
----------------------------+-------------------------------

Comment (by SergeyBiryukov):

 In [changeset:"48839" 48839]:
 {{{
 #!CommitTicketReference repository="" revision="48839"
 Code Modernization: Fix PHP 8 "ArgumentCountError: array_merge() does not
 accept unknown named parameters" fatal error in `retrieve_widgets()`.

 As per the documentation of `call_user_func_array()`, the `$param_arr`
 should be a (numerically) indexed array, not a string-keyed array.

 As we can use the spread operator in PHP 5.6+, there isn't really any need
 to use `call_user_func_array()` anyhow, we can call the `array_merge()`
 function directly.

 The caveat to this is that the spread operator only works on numerically
 indexed arrays, so we need to wrap the `$sidebars_widgets` variable in a
 call to `array_values()` when using the spread operator.

 Using `array_values()` in the existing `call_user_func_array()` call would
 also have solved this, but the solution now proposed, has the added
 benefit of getting rid of the overhead of `call_user_func_array()`.

 Props jrf.
 See #50913.
 }}}

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


More information about the wp-trac mailing list