找出定义自定义 PHP 函数的位置

Find out where custom PHP function is defined

我使用内部函数 function_exists,可以 return true 但是我在我的项目中找不到自定义函数。我还调试了我的代码来跟踪函数,但调试器没有进入我的自定义函数。我非常期待知道为什么。请帮帮我,谢谢。

要找出函数的定义位置,请使用以下代码:

<?php
   $rf = new ReflectionFunction('my_fuction_name');
   echo 'file:' . $rf->getFileName() . ', line:' . $rf->getStartLine();
?>

请注意,如果该函数未在源代码中定义,而是内部 PHP 函数,则 getFileName()getStartLine() 都将 return false.

您可以通过这种方式检查该函数是否为内部函数:

<?php
   $rf = new ReflectionFunction('my_fuction_name');
   if($rf->isInternal() === TRUE){
      echo "Function is internal!";
   }else{
      echo "Function is not internal.";
   }
?>