WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 5 months ago

#47465 new defect (bug)

current_action function - return types

Reported by: madeinua Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.3
Component: Administration Keywords: reporter-feedback needs-patch
Focuses: Cc:
PR Number:

Description

I received a PHP notice "Array to string conversion" that led me to the current_action() function in class-wp-list-table.php.

This function can return an array as a valid value. For example this request will return an array:

http://localhost/site/?action[]=1&action[]=2

But in this case:

PHPDoc is incorrect. Should be:

@return string|false|array

or/and

this may break some of the scripts that use this function. simply because they use the result value as a string. Possible solution: add an additional check: IF array THAN take only the first value of the result.

Thanks!

Attachments (1)

100644.patch (790 bytes) - added by madeinua 6 months ago.
Solution patch

Download all attachments as: .zip

Change History (4)

#1 @SergeyBiryukov
6 months ago

  • Component changed from General to Administration

@madeinua
6 months ago

Solution patch

#2 @SergeyBiryukov
6 months ago

  • Keywords reporter-feedback added

Hi @madeinua, welcome to WordPress Trac! Thanks for the ticket.

As noted in the documentation, WP_List_Table::current_action() returns the action selected from the Bulk Actions dropdown.

I haven't found any instances in core where $_REQUEST['action'] is an array. Do you have any examples that can be reproduced on a clean install, other than by directly editing the URL?

If some plugin uses $_REQUEST['action'] as an array for its own purposes, that sounds like a plugin issue, it should prefix the variable accordingly, e.g. my_plugin_action.

#3 @madeinua
5 months ago

Hello @SergeyBiryukov,

I agree there is no real example on a clean installation. But in this case you have to change the PHP Doc header (to add an array as a valid return type) because this can confuse the developers which will use this function in their plugins.

Note: See TracTickets for help on using tickets.