diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index bed67a9d9641c..3da3f5ac6a36d 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -507,11 +507,8 @@ function do_action( $hook_name, ...$arg ) { $wp_current_filter[] = $hook_name; } - if ( empty( $arg ) ) { + if ( array() === $arg ) { $arg[] = ''; - } elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) { - // Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`. - $arg[0] = $arg[0][0]; } $wp_filter[ $hook_name ]->do_action( $arg ); diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index fae2d736800f8..eee41ea096f58 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -133,6 +133,26 @@ public function action2( $arg ) { return $arg; } + /** + * @since 6.9.0 + */ + public function action3( array $arg ) { + $current_filter = $this->current_filter(); + + if ( $this->debug ) { + dmp( __FUNCTION__, $current_filter ); + } + + $this->events[] = array( + 'action' => __FUNCTION__, + 'hook_name' => $current_filter, + 'tag' => $current_filter, // Back compat. + 'args' => func_get_args(), + ); + + return $arg; + } + /** * @since UT (3.7.0) */ diff --git a/tests/phpunit/tests/actions.php b/tests/phpunit/tests/actions.php index ce4d896015ad6..e698ca0ef2cf9 100644 --- a/tests/phpunit/tests/actions.php +++ b/tests/phpunit/tests/actions.php @@ -209,24 +209,27 @@ public function test_action_args_3() { } /** - * Tests PHP 4 notation for calling actions while passing in an object by reference. + * One hook which is passed an array containing one object. This test ensures it will stay an array and not become an object. * * @ticket 48312 + * @ticket 60190 * * @covers ::do_action */ - public function test_action_args_with_php4_syntax() { + public function test_action_array_of_object_arg() { $a = new MockAction(); $hook_name = __FUNCTION__; $val = new stdClass(); + $arg = array( $val ); - add_action( $hook_name, array( &$a, 'action' ) ); - // Call the action with PHP 4 notation for passing object by reference. - do_action( $hook_name, array( &$val ) ); + add_action( $hook_name, array( $a, 'action3' ) ); + do_action( $hook_name, $arg ); $call_count = $a->get_call_count(); $argsvar = $a->get_args(); - $this->assertSame( array( $val ), array_pop( $argsvar ) ); + + // nested since func_get_args() returns the args as an array + $this->assertSame( array( $arg ), array_pop( $argsvar ) ); } /**