support for invokable objects (a.k.a. __invoke magic function)
-
I have Debug Bar Actions and Filters Addon version 1.5.1 and it lacks of support for invokable objects https://php.net/manual/en/language.oop5.magic.php#object.invoke .
when I register action or filter callable with invokable object plugin fails on function signature generation.
Code sample to reproduce the issue:
class InvokableClass {function __invoke() {/*code to run*/}} add_action('tag', new InvokableClass());
First error comes from wrong “Type 3 – closure within an array” detection on line 167
elseif ( ( is_array( $single_function['function'] ) || is_object( $single_function['function'] ) ) && dbafa_is_closure( $single_function['function'][0] ) )
should be
elseif ( is_array( $single_function['function'] ) && is_object( $single_function['function'][0] ) && dbafa_is_closure( $single_function['function'][0] ) )
Second error is when unique callback counting takes place on line 207. This happense due ‘Type 8 – undetermined’ handling. It do not set signature and because object is not convertable to string (due lack of __toString()) we get “PHP Catchable fatal error”.
I suggest to update “Type 8 – undetermined” handling by providing unique signature ex.
$signature = uniqid('undetermined_callback_');
for future.
Add support for invokable objects by adding new type like so:elseif ( is_object( $single_function['function'] ) && is_callable( $single_function['function'] ) ) { // Type 9 - closure within an array $signature = get_class( $single_function['function'] ) . ' -> __invoke'; $table .= '<li>[<em>' . esc_html__( 'object', 'debug-bar-actions-and-filters-addon' ) . '</em>] ' . $signature . '</li>'; }
Snippet must be added after closure detection, otherwise it will catch them.
- The topic ‘support for invokable objects (a.k.a. __invoke magic function)’ is closed to new replies.