如何让 php 获取调用函数的 __LINE__ 或 __FILE__ 值 [英] how to have php get the __LINE__ or __FILE__ value where a function is called

查看:29
本文介绍了如何让 php 获取调用函数的 __LINE__ 或 __FILE__ 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的 ZF 调试功能:

I have a ZF debug function like this:

function fs_d($d, $at){
    if($_REQUEST['debug']=='123'){
        Zend_Debug::dump($d,'at: ' . $at);
    }else{
        return true;
    }
}

并且会像这样调用:

fs_d($var, $at)

我希望 $at 表示在函数中调用 $at 的位置.换句话说,类似于 __LINE__ 处的 __FILE__ 在函数调用点而不是在输出点计算.但我不想在每次调用时都在 __LINE__ 处写入 __FILE__.

what I'd like $at to represent where $at was called in the function. In other words, something like __FILE__ at __LINE__ that is evaluated at point of function call and NOT at point of output. But I don't want to write __FILE__ at __LINE__ at every call.

有什么方法可以包装成宏,用括号括起来,{$} 或反引号之类的吗?

Is there some way to wrap as a macro, wrap in brackts, {$} or backticks or something?

推荐答案

http://www.php.net/debug_backtrace

$backtrace = debug_backtrace(false);
$last = $backtrace[1];
echo "Error in $last[file], line $last[line] ($last[function])!";

这篇关于如何让 php 获取调用函数的 __LINE__ 或 __FILE__ 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆