获取包含脚本的名称

时间:2013-08-03 17:33:19

标签: php

是否有一个魔术变量可以为我提供包含脚本的名称?

示例:

dashboard.php

<?php
include_once('test.php');

test.php的:

<?php
// Prints test.php
echo ___INCLUDING___;

1 个答案:

答案 0 :(得分:0)

来自an answer to Stack Overflow question Get name of file that is including a PHP script

<?php
    $trace = debug_backtrace();

    if (isset($trace[0])) {
        $includingScript = basename($trace[0]['file']);

        echo $includingScript;
    }
?>