Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 469
Justin Avatar asked Jun 20 '26 09:06

Justin


1 Answers

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.

like image 55
Wolfgang Stengel Avatar answered Jun 22 '26 23:06

Wolfgang Stengel