I\'m just playing around with the call_user_func function in PHP and am getting this error when running this simple code:
Alternatively to Omar's answer, you can also make printHi() a class static function, so you then can call it from call_user_func('A::printHi') , like this:
class A
{
public $var;
public static function printHi()
{
echo "Hello";
}
public function __construct($string)
{
$this->var = $string;
}
public function foo()
{
call_user_func($this->var);
}
}
$a = new A('A::printHi');
$a->foo();
See live example