[wp-trac] [WordPress Trac] #57887: The WordPress core does not support calling non-static methods for hook filters and actions within a namespace

WordPress Trac noreply at wordpress.org
Thu Mar 9 12:03:14 UTC 2023


#57887: The WordPress core does not support calling non-static methods for hook
filters and actions within a namespace
-------------------------------+-----------------------
 Reporter:  markcarbonell2013  |       Owner:  (none)
     Type:  defect (bug)       |      Status:  closed
 Priority:  normal             |   Milestone:
Component:  General            |     Version:
 Severity:  normal             |  Resolution:  invalid
 Keywords:                     |     Focuses:  rest-api
-------------------------------+-----------------------

Comment (by TobiasBg):

 Hi @markcarbonell2013,

 thanks for the confirmation!

 The deprecation warning is expected and correct here. Using `[__CLASS__,
 'do_something_non_static']` for a non-static method is incorrect. For non-
 static methods, you must use a reference to the object instance in the
 callback, like `$this` or a variable pointing to that object instance.
 So, in your case, you can use these two variants, depending on what you
 prefer:
 {{{
 add_action('foo', [__CLASS__ , 'do_something_static'], 10, 0);
 add_action('foo', [$this, 'do_something_non_static'], 10, 0);
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57887#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list