Php 如何获取运行该函数的函数?
我正在使用一个错误日志函数,我想包括在错误日志中发生错误的函数。是否有办法编写函数而不是每次都编写函数Php 如何获取运行该函数的函数?,php,Php,我正在使用一个错误日志函数,我想包括在错误日志中发生错误的函数。是否有办法编写函数而不是每次都编写函数 <?php $a = null; exampleFunction($a); function exampleFunction($variable){ if(is_null($variable)){ errorLog("variable is null. "); } } function errorLog($text){ error_log($text
<?php
$a = null;
exampleFunction($a);
function exampleFunction($variable){
if(is_null($variable)){
errorLog("variable is null. ");
}
}
function errorLog($text){
error_log($text, 3, ".testLog");
}
?>
您可以使用debug_backtrace获取函数调用堆栈的列表:
<?php
function foo()
{
bar();
}
function bar()
{
echo debug_backtrace()[1]['function'];
}
foo();
哇!令人惊叹的。非常感谢你。
<?php
function foo()
{
bar();
}
function bar()
{
echo debug_backtrace()[1]['function'];
}
foo();
foo