问题
Possible Duplicate:
PHP - retrieve name of script that included or required it
Is there a way in PHP
to get which file required/included
the current file? For example:
controller.php
<?php
include("add-person.php");
?>
add-person.php
<?php
echo get_parent(); //should return controller.php
?>
Execution
php -f controller.php
Basically, something like the made-up function get_parent()
. Thanks.
回答1:
I know of a "not so clean" way. Try going through the array debug_backtrace()
gives you. Among other things it contains a hierarchy how the code processed through include files. Manual here.
来源:https://stackoverflow.com/questions/11598363/php-get-which-file-included-required-current-file