dqcz57269 2012-01-19 06:44
浏览 8
已采纳

访问类的PHP函数[重复]

This question already has an answer here:

How to access the PHP function of a class where the function is stored in variable?

For example:

$functionname = "say_hello";
$obj = new Class();
$obj -> $functionname();
</div>
  • 写回答

3条回答 默认 最新

  • douchen9569 2012-01-19 06:57
    关注

    if function name is stored in a variable check if it is exists and is callable like

       if ( method_exists( $product, $method ) ) {
    print $product->$method(); // invoke the method
    }
    

    then check if it is callable

    if ( is_callable( array( $product, $method) ) ) {
    print $product->$method(); // invoke the method
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证