函数名称($ param,$ line = __LINE__,$ file = __FILE__){}; [英] function name($param, $line = __LINE__, $file = __FILE__) {};

查看:531
本文介绍了函数名称($ param,$ line = __LINE__,$ file = __FILE__){};的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能让一个函数自动包含行号和函数被调用的文件,

Is it possible to have a function automatically contain the line number and the file that the function was CALLED in,

好像我调用 __LINE __ __ FILE __ 在函数中它将使用函数定义所在的行和文件。

as if i call __LINE__ or __FILE__ in the function it will use the line and file the function definition is in.

但我不希望每次都要将 __ LINE __ __ FILE __ 传递给函数。

but i dont want to have to pass __LINE__ and __FILE__ into the function every time.

所以如果我将它们设置为默认参数,它们是来自函数定义还是来自它的调用?

so if i set them as the default params, do they come from the function definition, or where it is being called from?

推荐答案

唯一的方法是使用 debug_backtrace() ,但正如名称所示:它用于调试。您的代码应根据调用的地点/时间在生产中附加任何意义或功能。

The only way would be using debug_backtrace(), but as the name says: it is for debugging. Your code should not attach any meaning or functionality in production based on where/when it's called.

这篇关于函数名称($ param,$ line = __LINE__,$ file = __FILE__){};的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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