函数名称($ param,$ line = __LINE__,$ file = __FILE__){}; [英] function name($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屋!