[wp-trac] [WordPress Trac] #51986: PHP Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in class-wp-rest-server.php

WordPress Trac noreply at wordpress.org
Tue Sep 27 20:12:16 UTC 2022


#51986: PHP Warning: array_intersect_key(): Expected parameter 1 to be an array,
string given in class-wp-rest-server.php
-------------------------------------------+----------------------------
 Reporter:  slaFFik                        |       Owner:  davidbaumwald
     Type:  defect (bug)                   |      Status:  closed
 Priority:  normal                         |   Milestone:  6.1
Component:  Editor                         |     Version:  5.6
 Severity:  normal                         |  Resolution:  fixed
 Keywords:  php8 has-patch has-unit-tests  |     Focuses:  rest-api
-------------------------------------------+----------------------------
Changes (by davidbaumwald):

 * owner:  (none) => davidbaumwald
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"54339" 54339]:
 {{{
 #!CommitTicketReference repository="" revision="54339"
 REST API: Ensure `args` is an array of arrays in `register_rest_route()`.

 When calling `register_rest_route()`, the `args` parameter for a route
 should be an array of arrays.  However, some plugins/themes have passed an
 array of strings or key-value pairs which produces a PHP warning when
 `array_intersect_key` is used to filter the array keys based on an allowed
 list of schema keywords.

 This change adds a check of the `args` parameter to ensure it's an array
 of arrays, presenting a `_doing_it_wrong` if any element of `args` is not
 an array and restructuring to an array of arrays.  This change also adds a
 unit test for the incorrect usage described above, expecting that a
 `_doing_it_wrong` is produced.

 Props slaFFik, desrosj, apermo, AndrewNZ, aristath, poena, dovyp,
 timothyblynjacobs, Hinjiriyo, johnmark8080, nateallen.
 Fixes #51986.
 }}}

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


More information about the wp-trac mailing list