douxiangbiao1899
2013-05-24 17:01
浏览 215
已采纳

php通过字符串名称调用类函数

How can I call a normal (not static) class function by its name?

The below gives an error saying param 1 needs to be a valid callback. I don't want the function to be static, I want it to be a normal function, and all the examples I've seen so far had them static.

class Player
{
    public function SayHi() { print("Hi"); }
}

$player = new Player();

call_user_func($Player, 'SayHi');

图片转代码服务由CSDN问答提供 功能建议

如何通过名称调用普通(非静态)类函数?

下面给出了一个错误,说param 1需要是一个有效的回调。 我不希望函数是静态的,我希望它是一个普通的函数,到目前为止我见过的所有例子都是静态的。

  class Player  
 {
公共函数SayHi(){print(“Hi”);  } 
} 
 
 $ player = new Player(); 
 
call_user_func($ Player,'SayHi'); 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

相关推荐 更多相似问题