![]() |
How can I track errors from a called function?
I am not sure if this goes here but I am kinda beginning with PHP so I put it here, even though it might be a problem in a different level.
My problem is that i made a static query class to have more security in queries before sending them. But i want to know if there is an error in the query to tell me on which file on what line, the query method was called. like this: PHP Code:
PHP Code:
any advice or tips? |
Take a look at the function called debug_backtrace() and debug_print_backtrace() in your error handlers:
PHP: debug_print_backtrace - Manual PHP: debug_backtrace - Manual |
Oh they keep track of all the calls. That is more handy then the mess I've been trying to get. I'm going to incorporate it in the script and post the results, thanks.
|
Or, there is also the Reflection class (php 5+). It provides you waaay more info than that little function.
|
php 5.1.3 and above, to be exact, as I found out just recently.
*lurvs Reflection* ;-) |
wow, i should have read the whole oop section. this is good stuff. going to look at it.
Thanks |
Quote:
Combining a custom error handler set though set_error_handler() with debug_backtrace() makes it possible to show where the error occured where Reflection only can be used to extend the information from debug_backtrace() =) (That is if I understand his problem correctly ofcourse) |
No Kalle. You are not allowed to speak of such things. Reflection can do anything. ANYTHING.
|
Quote:
Try the getTrace method for an array containg all the trace info you need, and format it as you need, or, use the built-in getTraceAsString method, to get a default trace format. You can, of course, use something like this on the output: PHP Code:
The advantage of the exceptions is that you don't need to log the line on which an exception occured, nor the file in which the source code of the function/method was located. The exceptional engine keeps in mind all that stuff (and this is just the beginning of it) :) All you need to do is nicely ask for it. |
Quote:
|
Exceptional code (to be read code that throws exceptions) + reflection = the greatest debugging tool ever (and even documentation, why not). As someone said already, you can do just about anything with reflection.
|
Quote:
|
Except that, of course. And going to work instead of you. That's reflection weak points. But I'm sure the guys over at php.net work hardly on these issues :-P
|
Quote:
|
| All times are GMT. The time now is 10:38 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0