__FILE__ always replaced by the name of the file in which the symbol appears.
To get the name of the file from which the function was called, you can use debug_backtrace() . This returns the current column as an array, with each auxiliary array containing the files, rows, and function keys from which the call was made.
You can drag the front element from the array to get the location from which the function is called:
A.php:
<?php require_once('b.php'); b();
b.php:
<?php function b() { $bt = debug_backtrace(); var_export($bt); }
output:
array ( 0 => array ( 'file' => '/home/meagar/a.php', 'line' => 5, 'function' => 'b', 'args' => array( ), ), )
The same thing works without function calls:
A.php:
<?php require_once('b.php');
b.php:
<?php $bt = debug_backtrace(); var_export($bt);
output:
array ( 0 => array ( 'file' => '/home/meagar/a.php', 'line' => 3, 'function' => 'require_once', ), )
source share