mrherman Posted July 15, 2008 Share Posted July 15, 2008 Hello, friends! I searched the PHP HELP forum for this, but didn't find anything. (There must be a good reason that perhaps no one has asked about this previously.) I want to send an error message, and I want the error message to include the current PHP script line number, how might I do this? Something like... if (x <> y) { die("Not a match...Line num: " . get_current_line()); } I have an idea that this is not feasible, but just need confirmation. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/114826-solved-in-a-proprietary-error-msg-is-there-a-way-to-generate-the-current-line-num/ Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 if (x <> y) { die("Not a match...Line num: " . __LINE__); } Quote Link to comment https://forums.phpfreaks.com/topic/114826-solved-in-a-proprietary-error-msg-is-there-a-way-to-generate-the-current-line-num/#findComment-590425 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 if you want a detailed error report see the manual for "set_error_handler" fourth parameter (contains the line number the error was raised at, as an integer. ) you should be able to convert this to an email instead of display <?php // error handler function function myErrorHandler($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_ERROR: echo "<b>My ERROR</b> [$errno] $errstr<br />\n"; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; exit(1); break; case E_USER_WARNING: echo "<b>My WARNING</b> [$errno] $errstr<br />\n"; break; case E_USER_NOTICE: echo "<b>My NOTICE</b> [$errno] $errstr<br />\n"; break; default: echo "Unknown error type: [$errno] $errstr<br />\n"; break; } /* Don't execute PHP internal error handler */ return true; } // set to the user defined error handler $old_error_handler = set_error_handler("myErrorHandler"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114826-solved-in-a-proprietary-error-msg-is-there-a-way-to-generate-the-current-line-num/#findComment-590428 Share on other sites More sharing options...
mrherman Posted July 15, 2008 Author Share Posted July 15, 2008 Thank you, Thorpe and MadTechie -- This is most helpful! Quote Link to comment https://forums.phpfreaks.com/topic/114826-solved-in-a-proprietary-error-msg-is-there-a-way-to-generate-the-current-line-num/#findComment-590452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.