note 75057 deleted from function.trigger-error by nlopess

From: Date: Sat, 12 May 2007 11:28:42 +0000
Subject: note 75057 deleted from function.trigger-error by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126443@lists.php.net to get a copy of this message
Note Submitter: MLxS ---- Wolverine: I would consider myself an expert novice, if you can be such a thing, so this might not be the correct or best way - but it seems to work! I also found this problem annoying as I wanted to add a debug after every sql_query (since sql_query errors aren't logged) and didn't want to have to continually write all the information each time! After much searching I have scrambled something together that will (almost) certainly work as an answer. Note: You could also investigate the set_error_handler which you can then use to alter all the error messages! (Message me from www.moonlight-solutions.co.uk if you want more info) Here is the code I have used to get round it! I guess you will probably be able to use a similar function. Note that the error_log function will only output the timestamp by default. The final argument '0' in the error_log function orders php to put the output to the usual error output. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function my_nice_function ($my_arg) { if ($my_arg != "My Chosen Value") { $calling_function = debug_backtrace(); error_log("My Custom Error. This error happened in " . $calling_function['0']['file'] . " on line " . $calling_function['0']['line'], 0); } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Output e.g. [10-May-2007 12:04:20] My Custom Error. This error happened in c:\server\wwwroot\public_html\mine.php on line 123 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The debug_backtrace is the function that does the work and has been included since 4.3.0. error_log is included from PHP 3. debug_backtrace creates an associative array, and since we want the most recent calling function we use ['0'], but see the manual for more info. Hope this helps with this annoying problem!

« previous php.notes (#126443) next »