【问题标题】:PHP get which file included/required current file [duplicate]PHP获取包含/需要当前文件的文件[重复]
【发布时间】:2012-07-20 20:27:39
【问题描述】:

可能重复:
PHP - retrieve name of script that included or required it

PHP 中有没有办法获取当前文件required/included 的哪个文件?例如:

controller.php

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

add-person.php

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

执行

php -f controller.php

基本上,类似于编造的函数get_parent()。谢谢。

【问题讨论】:

    标签: php include require


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 2016-09-02
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 2019-02-25
      • 2015-01-12
      相关资源
      最近更新 更多