您的当前位置:首页>全部文章>文章详情

php 获取函数所在的文件名

发表于:2023-05-29 22:38:01浏览:517次TAG: #PHP #ThinkPHP
function function_dump($funcname) {  
        try {  
            if(is_array($funcname)) {  
                $func = new ReflectionMethod($funcname[0], $funcname[1]);  
                $funcname = $funcname[1];  
            } else {  
                $func = new ReflectionFunction($funcname);  
            }  
        } catch (ReflectionException $e) {  
            echo $e->getMessage();  
            return;  
        }  
        $start = $func->getStartLine() - 1;  
        $end =  $func->getEndLine() - 1;  
        $filename = $func->getFileName();  
        echo "function $funcname defined by $filename($start - $end)\n";  
    }