Re: Function call stack
| From: | Stefan Rusterholz | Date: | Wed, 30 Jan 2002 13:11:57 +0000 |
| Subject: | Re: Function call stack | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82728@lists.php.net to get a copy of this message | ||
If you set_error_handler, then you get automatically line number and
filename.
Read through: http://www.php.net/manual/en/function.set-error-handler.php
(read user comments! there are undocumented things)
Then set up your handler like this:
$_old_error_handler = set_error_handler("myErrorHandler");
function somefunction(){
#do some stuff
trigger_error("Something went wrong, don't know why, sorry",
E_USER_ERROR);
}
function myErrorHandler($level, $message, $file, $line, $context){ #$context
contains _ALL_ variabels in scope when error happened
echo "D'oh, an error has occurred: $message.\n";
echo "It happened in file $file at line $line and it is a $level-error";
}
the most beauty about that is that you can also cover errors you didn't
handle (e.g. if fopen triggers a warning or whatever)
best regards
stefan rusterholz
----- Original Message -----
From: "Lars Torben Wilson" <torben@php.net>
To: "Christian Novak" <cnovak@gmx.net>
Cc: <php-general@lists.php.net>
Sent: Wednesday, January 30, 2002 12:45 PM
Subject: Re: [PHP] Function call stack
> On Wed, 2002-01-30 at 03:33, Christian Novak wrote:
> > Has anyone an idea on how to get information from PHP on the function
call
> > stack.
> > I need the line number and file calling a function for a custom error
> > handler.
>
> This cannot be done in current versions of PHP. There are
> feature requests in the bug database about this, though.
>
>
> Torben
>
> > To be more clear, here is what I would like to do:
> >
> > - I have a library, included in the main program
> > - I have an error handler in the library
> >
> > // main.php
> > require "library.php";
> > $x = myfunc('A');
> >
> >
> > // library.php
> > function myfunc($i)
> > {
> > if (!is_int($i)) {
> > $file = ???? // how can I get the file name of the file
> > calling myfunc()
> > $line = ???? // how can I get the line number of the file
> > calling myfunc()
> > trigger_error("Error in $file, at line $line, paramter must be an
> > integer!", E_USER_ERROR);
> > return($i);
> >
> > Using the pre_defined varibales __line__ and __file__ will always point
me
> > to the function not the calling
> > script.
> >
> > Best regards
> >
> > Christian Novak
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> >
> --
> Torben Wilson <torben@php.net>
> http://www.thebuttlesschaps.com
> http://www.hybrid17.com
> http://www.inflatableeye.com
> +1.604.709.0506
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>