Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.