PHP get which file included/required current file [duplicate]

假装没事ソ 提交于 2019-12-10 18:19:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!