Php 使用magic contant类返回调用类的文件路径

Php 使用magic contant类返回调用类的文件路径,php,constants,Php,Constants,我一直在使用下面的语句返回方法的文件路径和行号 echo (__METHOD__) . "() - ln : " . (__LINE__) . "<br />"; 并让它返回调用代码的文件路径。我尝试了一些变体,但我遗漏了一些东西。你能帮忙吗 谢谢试试: echo __FILE__; 尝试: 签出-这可以为您提供所需的来电者信息 例如: <?php class comment { public static function show() {

我一直在使用下面的语句返回方法的文件路径和行号

echo (__METHOD__) . "() - ln : " . (__LINE__) . "<br />";
并让它返回调用代码的文件路径。我尝试了一些变体,但我遗漏了一些东西。你能帮忙吗

谢谢

试试:

echo __FILE__;
尝试:

签出-这可以为您提供所需的来电者信息

例如:

<?php

class comment
{
    public static function show()
    {
            $trace=debug_backtrace();
            print_r($trace);
    }

    public function test()
    {
         comment::show();
    }

}

$comment=new comment();
$comment->test();
第一个元素显示调用方的详细信息-根据您的喜好设置格式,如果有帮助,还可以显示整个调用堆栈

签出-这可以为您提供所需的来电者信息

例如:

<?php

class comment
{
    public static function show()
    {
            $trace=debug_backtrace();
            print_r($trace);
    }

    public function test()
    {
         comment::show();
    }

}

$comment=new comment();
$comment->test();

第一个元素显示调用方的详细信息-根据您的喜好设置格式,如果有帮助,还可以显示整个调用堆栈

是否返回文件路径或方法名称和行号?是否返回文件路径或方法名称和行号?
<?php

class comment
{
    public static function show()
    {
            $trace=debug_backtrace();
            print_r($trace);
    }

    public function test()
    {
         comment::show();
    }

}

$comment=new comment();
$comment->test();
 Array
(
    [0] => Array
        (
            [file] => /tmp/test.php
            [line] => 13
            [function] => show
            [class] => comment
            [type] => ::
            [args] => Array()

        )

    [1] => Array
        (
            [file] => /tmp/test.php
            [line] => 19
            [function] => test
            [class] => comment
            [object] => comment Object ()
            [type] => ->
            [args] => Array()

        )

)