php call class function by string name

The callback syntax is a little odd in PHP. What you need to do is make an array. The 1st element is the object, and the 2nd is the method.

call_user_func(array($player, 'SayHi'));

You can also do it without call_user_func:

$player->{'SayHi'}();

Or:

$method = 'SayHi';
$player->$method();

Leave a Comment