PHP获取包含/所需当前文件的文件 [英] PHP get which file included/required current file

查看:89
本文介绍了PHP获取包含/所需当前文件的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PHP - 检索包含或要求它的脚本名称

PHP 中是否有办法获取所需/包含的文件当前的文件?例如:

Is there a way in PHP to get which file required/included the current file? For example:

<?php
  include("add-person.php");
?>



add-person.php



add-person.php

<?php
  echo get_parent(); //should return controller.php
?>



执行



Execution

php -f controller.php

基本上就像伪造的功能 get_parent()。谢谢。

Basically, something like the made-up function get_parent(). Thanks.

推荐答案

我知道不太干净的方式。尝试通过数组 debug_backtrace()给你。除其他外,它包含一个层次结构,代码如何通过包含文件进行处理。手动此处

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.

这篇关于PHP获取包含/所需当前文件的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆