Re: Which file called the function?
| From: | Richard Lynch | Date: | Thu, 20 Dec 2007 19:22:02 +0000 |
| Subject: | Re: Which file called the function? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-266176@lists.php.net to get a copy of this message | ||
On Thu, December 20, 2007 8:37 am, Christoph Boget wrote:
> Let's say I have the following 3 files
>
> global.php
> <?
> function myFunc() { echo __FILE__; }
> ?>
>
> one.php
> <?
> include( 'global.php' );
> echo 'You are in file: ';
> myFunc();
> ?>
>
> two.php
> <?
> include( 'global.php' );
> echo 'You are in file: ';
> myFunc();
> ?>
>
> In each case, what is echoed out for __FILE__ is global.php. Apart
> from
> analyzing the debug_backtrace array, is there any way that myFunc()
> would
> display "one.php" and "two.php" respectively?
$_SERVER['PHP_SELF'] and other bits in $_SERVER have the "main" PHP
filename in them.
__FILE__ will always be exactly the file that it's in.
In between, I think you are stuck with the debug_backtrace.
NOTE:
If it's for error logging or error reporting, note that trigger_error
automatically passes in the file/line to the error handler.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?