Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP,如何获取正在运行的函数的名称?_Php - Fatal编程技术网

PHP,如何获取正在运行的函数的名称?

PHP,如何获取正在运行的函数的名称?,php,Php,我正在使用一个错误日志函数,我想包括在错误日志中发生错误的函数。是否有办法编写函数而不是每次都编写函数 <?php $a = null; exampleFunction($a); function exampleFunction($variable){ if(is_null($variable)){ errorLog("variable is null. Function : exampleFunction()"); } } function errorL

我正在使用一个错误日志函数,我想包括在错误日志中发生错误的函数。是否有办法编写函数而不是每次都编写函数

<?php 

$a = null;

exampleFunction($a);

function exampleFunction($variable){

  if(is_null($variable)){

    errorLog("variable is null. Function : exampleFunction()");

  }

}

function errorLog($text){

 error_log($text, 3, ".testLog");

}

?>

是的,您可以使用
\u函数\u
常量。它是(2个下划线)“函数”(2个下划线)

如果你想更进一步,如果它在课堂上

echo "The class name is " . __CLASS__ . " and the function is " . __FUNCTION__;

为此,您可以使用uu函数uu

尝试
u函数uu
。正如链接的答案所示:在您的errorLog函数中,您可以引用:
debug_backtrace()[1]['FUNCTION']
。我错过了它。这个解决方案奏效了。非常感谢你@Progrocklol。在这里写双下划线很棘手。如果没有转义,它们会将文本变为粗体。您还可以使用代码标记使_下划线____)不会导致粗体文本。
function whatever($stuff){
echo "The function name is " . __FUNCTION__;
}
echo "The class name is " . __CLASS__ . " and the function is " . __FUNCTION__;