Skip to content

Commit 25ed69e

Browse files
committed
drop support for PHP 4 in favor of PHP 7+ native types
1 parent f9b59e9 commit 25ed69e

3 files changed

Lines changed: 44 additions & 25 deletions

File tree

src/wp-includes/plugin.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,8 @@ function do_action( $hook_name, ...$arg ) {
507507
$wp_current_filter[] = $hook_name;
508508
}
509509

510-
if ( empty( $arg ) ) {
510+
if ( array() === $arg ) {
511511
$arg[] = '';
512-
} elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) {
513-
// Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`.
514-
$arg[0] = $arg[0][0];
515512
}
516513

517514
$wp_filter[ $hook_name ]->do_action( $arg );

tests/phpunit/includes/utils.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ public function action2( $arg ) {
133133
return $arg;
134134
}
135135

136+
/**
137+
* @since 6.6.0
138+
*/
139+
public function action3( array $arg ) {
140+
$current_filter = $this->current_filter();
141+
142+
if ( $this->debug ) {
143+
dmp( __FUNCTION__, $current_filter );
144+
}
145+
146+
$this->events[] = array(
147+
'action' => __FUNCTION__,
148+
'hook_name' => $current_filter,
149+
'tag' => $current_filter, // Back compat.
150+
'args' => func_get_args(),
151+
);
152+
153+
return $arg;
154+
}
155+
136156
/**
137157
* @since UT (3.7.0)
138158
*/

tests/phpunit/tests/actions.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ public function test_has_action() {
9696
$this->assertFalse( has_action( $hook_name ) );
9797
}
9898

99+
/**
100+
* One tag with array with 1 object to ensure it will stay an array and not become an object
101+
*
102+
* @ticket 60190
103+
*
104+
* @covers ::do_action
105+
*/
106+
public function test_action_array_of_object_arg() {
107+
$a = new MockAction();
108+
$hook_name = __FUNCTION__;
109+
$val = new stdClass();
110+
$arg = array( $val );
111+
112+
add_action( $hook_name, array( $a, 'action3' ) );
113+
do_action( $hook_name, $arg );
114+
115+
$call_count = $a->get_call_count();
116+
$argsvar = $a->get_args();
117+
118+
// nested since func_get_args() returns the args as an array
119+
$this->assertSame( array( $arg ), array_pop( $argsvar ) );
120+
}
121+
99122
/**
100123
* One tag with multiple actions.
101124
*
@@ -208,27 +231,6 @@ public function test_action_args_3() {
208231
$this->assertSame( array( $val1, $val2 ), array_pop( $argsvar3 ) );
209232
}
210233

211-
/**
212-
* Tests PHP 4 notation for calling actions while passing in an object by reference.
213-
*
214-
* @ticket 48312
215-
*
216-
* @covers ::do_action
217-
*/
218-
public function test_action_args_with_php4_syntax() {
219-
$a = new MockAction();
220-
$hook_name = __FUNCTION__;
221-
$val = new stdClass();
222-
223-
add_action( $hook_name, array( &$a, 'action' ) );
224-
// Call the action with PHP 4 notation for passing object by reference.
225-
do_action( $hook_name, array( &$val ) );
226-
227-
$call_count = $a->get_call_count();
228-
$argsvar = $a->get_args();
229-
$this->assertSame( array( $val ), array_pop( $argsvar ) );
230-
}
231-
232234
/**
233235
* @ticket 60193
234236
*

0 commit comments

Comments
 (0)