Re: [PHP] How can i get the location of an exit()/die() from within register_shutdown_function()?
- From: eric.butera@xxxxxxxxx ("Eric Butera")
- Date: Wed, 16 Jul 2008 09:15:07 -0400
On Wed, Jul 16, 2008 at 3:23 AM, Mathijs van Veluw
<mathijs.van.veluw@xxxxxxxxxxx> wrote:
Hello there,
I have an shutdown function to catch fatal-errors etc..
Now when there is an exit() somewhere i get an empty message from
get_last_error().
I want to know the location of this exit() or die().
Is there a way to get the file and line-number from where the exit/die
originated?
Thx in advance.
The way I handle this is by throwing exceptions in my code. So let's
say that there is a db connection/query failure for whatever reason.
Instead of using query() or die() which is not user friendly, I throw
an exception which bubbles up. Once it hits the top then I can catch
it, log it accordingly, and show the user a friendlier error page
saying Oops!
With an exception you get exactly what you want, a full-blown stack
trace complete with paths, line numbers etc. You also get the ability
to be graceful about what you show to the end user.
....but I have the feeling that you're already dealing with a situation
in lots of existing code. Perhaps you could combine some suggestions
in this thread and replace your die/exit statements with a custom
function which logs a debug_backtrace() and then really dies, but
gracefully of course. :)
As an aside, if I were to see some jibberish about a query and line
numbers when I click a link I'd leave that site. (And for the
archives) It is a security vuln to show full file paths to an end
user. If someone is tampering with your system we shouldn't give them
any more information than they can already get.
.
- Follow-Ups:
- References:
- How can i get the location of an exit()/die() from within register_shutdown_function()?
- From: Mathijs van Veluw
- How can i get the location of an exit()/die() from within register_shutdown_function()?
- Prev by Date: RE: [PHP] Downloading a file
- Next by Date: Re: [PHP] How can i get the location of an exit()/die() from within register_shutdown_function()?
- Previous by thread: Re: [PHP] How can i get the location of an exit()/die() from within register_shutdown_function()?
- Next by thread: Re: [PHP] How can i get the location of an exit()/die() from within register_shutdown_function()?
- Index(es):