[wp-trac] [WordPress Trac] #60190: Drop PHP 4 support for arrays with 1 object element
WordPress Trac
noreply at wordpress.org
Fri May 23 11:59:44 UTC 2025
#60190: Drop PHP 4 support for arrays with 1 object element
-------------------------------------------------+-------------------------
Reporter: kkmuffme | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.9
Component: Plugins | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests early 2nd- | Focuses:
opinion |
-------------------------------------------------+-------------------------
Changes (by johnbillion):
* keywords: has-patch has-unit-tests early => has-patch has-unit-tests
early 2nd-opinion
Comment:
To clarify about the fatal error: this isn't actually related to native
type handling, that's just where the fatal error occurs when a callback
function receives an object as its first parameter instead of the expected
array containing an object. The underlying problem is, as @kkmuffme
mentions, that `do_action` will convert arrays with only 1 object into
that object before passing it to the callbacks. Regardless of whether a
callback uses a type declaration, it'll receive a value of the wrong type
as its first parameter.
While I'm in favour of the fix and the tests in
https://github.com/WordPress/wordpress-develop/pull/5839 I'm concerned
about what might break. This is essentially a revert of [46568]. #48312
provides an example of code that will behave differently after this fix:
{{{#!php
do_action( 'some_action', array( $this ) );
}}}
Currently a callback hooked into this action receives the object as its
first parameter instead of an array containing the object. This proposed
change "fixes" that but will break any existing code that works around
this funky behaviour.
Does the fix justify the back-compat break?
CC @david.binda @SergeyBiryukov @azaozz
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60190#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list