doushui5587 2011-03-23 07:16
浏览 67
已采纳

在PHP中输出调用函数信息

Consider this code :

class App {
    public static function log($msg) {
    echo $msg;
    //echo WHAT_CLASS_CALLED_LOG;
    //echo WHAT_LINE_CALLED_LOG;
}
}


class Tester {
public function Make() {
    App::log('test');
}
}


$obj = new Tester();
$obj->Make();

Is is possible to get the class name and the function name of the calling function in the log method ? ( without explicitly sending them to the log function )

PS : I think trigger_error works like that behind the curtains so I was wondering If I can achieve this.

  • 写回答

2条回答 默认 最新

  • douqingzhi0980 2011-03-23 07:22
    关注

    I believe you're looking for debug_backtrace.

    Returns an associative array. The possible returned elements are as follows: 
    
    Name        Type    Description
    function    string  The current function name. See also __FUNCTION__.
    line        integer The current line number. See also __LINE__.
    file        string  The current file name. See also __FILE__.
    class       string  The current class name. See also __CLASS__
    object      object  The current object.
    type        string  The current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned.
    args        array   If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s). 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路