I was looking through the WordPress plugin and I saw this function in the class constructor:
add_action('init', array($this, 'function_name'));
I searched and found what array($this, 'function_name')is a valid callback. I do not understand: why use this method instead of using$this->function_name();
Here is a sample code:
class Hello{
function __construct(){
add_action('init', array($this, 'printHello'));
}
function printHello(){
echo 'Hello';
}
}
$t = new Hello;
source
share