Jump to content

[SOLVED] In a proprietary error msg., is there a way to generate the current line num.?


mrherman

Recommended Posts

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!

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 :P

 

<?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");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.