note 75057 added to function.trigger-error

From: Date: Thu, 10 May 2007 11:20:00 +0000
Subject: note 75057 added to function.trigger-error
Groups: php.notes 
Request: Send a blank email to php-notes+get-126383@lists.php.net to get a copy of this message
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! ---- Server IP: 194.145.210.3 Probable Submitter: 62.31.191.176 ---- Manual Page -- http://www.php.net/manual/en/function.trigger-error.php Edit -- https://master.php.net/note/edit/75057 Del: integrated -- https://master.php.net/note/delete/75057/integrated Del: useless -- https://master.php.net/note/delete/75057/useless Del: bad code -- https://master.php.net/note/delete/75057/bad+code Del: spam -- https://master.php.net/note/delete/75057/spam Del: non-english -- https://master.php.net/note/delete/75057/non-english Del: in docs -- https://master.php.net/note/delete/75057/in+docs Del: other reasons-- https://master.php.net/note/delete/75057 Reject -- https://master.php.net/note/reject/75057 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126383) next »