Title: support for invokable objects (a.k.a. __invoke magic function)
Last modified: September 18, 2016

---

# support for invokable objects (a.k.a. __invoke magic function)

 *  Resolved [eimanavicius](https://wordpress.org/support/users/nerijus-eimanaviius/)
 * (@nerijus-eimanaviius)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/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 [http://php.net/manual/en/language.oop5.magic.php#object.invoke](http://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.
    -  This topic was modified 9 years, 8 months ago by [eimanavicius](https://wordpress.org/support/users/nerijus-eimanaviius/).
    -  This topic was modified 9 years, 8 months ago by [eimanavicius](https://wordpress.org/support/users/nerijus-eimanaviius/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Subharanjan](https://wordpress.org/support/users/subharanjan/)
 * (@subharanjan)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/support-for-invokable-objects-a-k-a-__invoke-magic-function/#post-8196724)
 * Thank you for reporting the issue and for the suggestion. I will have a look 
   and release a new version with a patch.
 * Thanks !!
 *  Thread Starter [eimanavicius](https://wordpress.org/support/users/nerijus-eimanaviius/)
 * (@nerijus-eimanaviius)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/support-for-invokable-objects-a-k-a-__invoke-magic-function/#post-8539741)
 * Hi, I’m still waiting on this fix.
 *  Plugin Author [Subharanjan](https://wordpress.org/support/users/subharanjan/)
 * (@subharanjan)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/support-for-invokable-objects-a-k-a-__invoke-magic-function/#post-8539778)
 * Hi Nerijius,
 * I am sorry about the delay.
 * I will work on it and release soon. You can track the progress through this ticket
   [https://github.com/subharanjanm/debug-bar-actions-and-filters-addon/issues/19#issuecomment-266203422](https://github.com/subharanjanm/debug-bar-actions-and-filters-addon/issues/19#issuecomment-266203422)
 * Thanks for your patience.
 * Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘support for invokable objects (a.k.a. __invoke magic function)’ is closed
to new replies.

 * ![](https://ps.w.org/debug-bar-actions-and-filters-addon/assets/icon-256x256.
   png?rev=972076)
 * [Debug Bar Actions and Filters Addon](https://wordpress.org/plugins/debug-bar-actions-and-filters-addon/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/debug-bar-actions-and-filters-addon/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/debug-bar-actions-and-filters-addon/)
 * [Active Topics](https://wordpress.org/support/plugin/debug-bar-actions-and-filters-addon/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/debug-bar-actions-and-filters-addon/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/debug-bar-actions-and-filters-addon/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Subharanjan](https://wordpress.org/support/users/subharanjan/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/support-for-invokable-objects-a-k-a-__invoke-magic-function/#post-8539778)
 * Status: resolved