hmmm, i spent now a lot of time searching for such a function (discovering
many many to me unknown but interesting functions :) - but it seems that
there is no such function.

And yes: I wanted to use it for debugging stuff. I have a lot of recursive
functions and callback functions and it's sometimes incredibly hard to
determine when exactly an error happened because I don't know the how
maniest instance of a function actually is running and from where it got
called. I have made some workarounds, but they are all unsatisfying compared
to the possibilities a stacktrace function would offer...

Just to give you a little impression what perl has got for such things (and
i'd love to see that or something similar in PHP) an extract from the
manual:
caller EXPR

caller

Returns the context of the current subroutine call. In scalar context,
returns the caller's package name if there is a caller, that is, if we're in
a subroutine or eval or require, and the undefined value otherwise. In list
context, returns
    ($package, $filename, $line) = caller;
With EXPR, it returns some extra information that the debugger uses to print
a stack trace. The value of EXPR indicates how many call frames to go back
before the current one.

    ($package, $filename, $line, $subroutine, $hasargs,
    $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller($i);
Here $subroutine may be (eval) if the frame is not a subroutine call, but an
eval. In such a case additional elements $evaltext and $is_require are set:
$is_require is true if the frame is created by a require or use statement,
$evaltext contains the text of the eval EXPR statement. In particular, for
an eval BLOCK statement, $filename is (eval), but $evaltext is undefined.
(Note also that each use statement creates a require frame inside an eval
EXPR) frame. $hasargs is true if a new instance of @_ was set up for the
frame. $hints and $bitmask contain pragmatic hints that the caller was
compiled with. The $hints and $bitmask values are subject to change between
versions of Perl, and are not meant for external use.

Furthermore, when called from within the DB package, caller returns more
detailed information: it sets the list variable @DB::args to be the
arguments with which the subroutine was invoked.

Be aware that the optimizer might have optimized call frames away before
caller had a chance to get the information. That means that caller(N) might
not return information about the call frame you expect it do, for N > 1. In
particular, @DB::args might have information from the previous time caller
was called.

----- Original Message -----
From: "Martin Wickman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, January 14, 2002 10:24 AM
Subject: [PHP] Re: How to get a function backtrace?


> Stefan Rusterholz wrote:
>
> > Im not sure if "function-backtrace" is the correct word for what I need,
so I'll explain:
> > If I have for example
>
>
> What you are looking for is a "stacktrace", ie the stack of called
> functions. Dunno if php has any support for it, but it is normally
> used when debugging and error/exception handling.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to