WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 3 months ago

#47438 new defect (bug)

do_action will convert "single array object" as "object"

Reported by: erikdemarco Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.1.1
Component: Plugins Keywords:
Focuses: Cc:
PR Number:

Description

/* Correct if $object is not object*/
$orders = array();
$orders[] = 'abc';

do_action( 'action123', $orders); 

add_action('action123', 'func123');
function func123($orders){
	//$orders will be array here (CORRECT)
}


/* BUG: if $orders is an object */
$orders = array();
$orders[]=new stdClass();
$orders->name='Order1';

do_action( 'action123', $orders); 

add_action('action123', 'func123');
function func123($orders){
	//$orders will be non-array here (BUG?)
}

Note:
This will run correctly if $orders[] is not object

Change History (3)

#1 @erikdemarco
8 months ago

this bug has been there since 2 years ago

see contributed notes here:
https://developer.wordpress.org/reference/functions/do_action/

#2 @SergeyBiryukov
8 months ago

  • Component changed from General to Plugins

#3 @dlh
3 months ago

#48382 was marked as a duplicate.

Note: See TracTickets for help on using tickets.