RE: Which file called the function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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.

I'm far from being an expert, and often see more efficient ways of doing
things (more efficient tham my own methods). Howevr, I've just been dealing
with a similar problem.

I have a functions file with over 400 functions (and that may be too many -
but it works). I've been adding some error reporting in to my PEAR::DB
queries, but wanted to know which page triggered the function. I went
theough my php pages and gane each one a $pg variable at the start
containing the bare name of the file, eg 'home' rather than 'home.php'. I
then went to each function containing either a DB query (ore one which calls
another DB-related function. I did a global search and replace for the
function name 'func(' replaced by 'func($pg,'. I use Dreamweaver so this was
fairly straightforward.

It worked for me, but now someone is about to show me a quicker, cleaner
way, aren't they?

Cheers, and seasonal greetings from Oxford/Edinburgh

George

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux