Ok, here is a real short query.
I am calling __FILE__ from inside a function.
Now, this function itself is in a required file.
Now, when I call this function from inside the Parent file, will the __FILE__ output the parent file or the file which was included?
Oh, and I am looking for a source where I can confirm, if possible, because my tests here are giving me entirely absurd results.
Also, if this should display the child (included) file, how should I go about it so that it rather displays the parent filepath? (some variation or something?)
__FILE__is always replaced with the filename in which the symbol appears.To get the name of the file from which a function was called, you can use
debug_backtrace(). This returns the current callstack as an array, with each sub-array containing the file, line and function keys from which the call was made.You can shift the front-most element off the array to get the location from which a function was called:
a.php:
b.php:
output:
The same thing works without function calls:
a.php:
b.php:
output: