Posted by Kimmo Laine on 09/21/05 12:53
"Anze" <anzenews@volja.net> wrote in message
news:1T9Ye.317$h6.109140@news.siol.net...
> Hi all!
>
> Is it possible (in PHP4 and PHP5) to get the filename and line number of
> the
> call to the current function? I need it for debugging purposes:
>
> function query_DB($sql) {
> ... // do a query here
>
> if ($query_failed)
> write_to_log($fail_reason."; Called from ".$__CALLING_FILE__.
> " line: ".__CALLING_LINE__);
>
> ... // return result
> }
>
> __FILE__ and __LINE__ are not good enough - they will always return the
> address of query_DB() function, but I need the address where the function
> was called (this is where the error comes from).
Looks like you need debug_backtrace() (available since PHP4.3)
http://www.php.net/manual/en/function.debug-backtrace.php
In short: it traces the origin of the function call and generates an array
of the trace.
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
antaatulla.sikanautaa@gmail.com.NOSPAM.invalid
Navigation:
[Reply to this message]
|