LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP Function to return the most recent error. (https://www.linuxquestions.org/questions/programming-9/php-function-to-return-the-most-recent-error-186478/)

id10t 05-27-2004 08:23 AM

PHP Function to return the most recent error.
 
I want a function that I can use to return the most recent error and error no. for an error function that I am putting together.

I have seen a lot of functions like mysql_error() and hw_error(), but I want one that would be general... Is there one standard, or will I have to make my own?

::Edit::
I am using PHP vers 4.3.6, but would be willing to hop over to ver 5

keefaz 05-27-2004 10:21 AM

http://fr2.php.net/manual/en/ref.errorfunc.php

edit : found the good url

id10t 05-27-2004 12:18 PM

It is still kind of a problem... I don't think I explained well enough.

I need a function that I can call anywhere I want to, to return me the last error that happened in the script. The set_error_handler function won't do that job. I can have the script automatically do certain things on error with that, but I want the errors to be more in my own control.

Most notices I would want the user to never see and the script to keep running, but every now and then there is one I feel the user should be aware of. I want to be able to use this function as I see fit... Such as.

Code:

if($result = @mysql_query($query)){
  my_error_handler("notify-user", "pop-up", "feedback");
}

So for the function, I would want to be able to work together an error string such as.
Code:

$errorno  = error_no_function_I_need();
$errormsg = error_msg_function_I_need();
$devdesc  = "My description for the user.";

$errorstr = "Error Number " . $errorno . ":  " . 
            $errormsr . "<br />" . $devdesc;


id10t 05-27-2004 12:19 PM

Now that I think of it, a function that would grab the current line and file-name/path would be pretty sweet too.

keefaz 05-27-2004 04:12 PM

You may look at http://fr2.php.net/manual/en/function.error-log.php and once your error log you have an error history which you can play with it.

And for : "a function that would grab the current line and file-name/path", there is an example at the URL I wrote above

id10t 05-30-2004 06:24 PM

__LINE__ Is a pseudo constant that contains the corrent line number.
__FILE__ Is a pseudo constant that contains the current filename.

if you go into the php.ini file and change track_errors from Off to On:
$php_errormsg contains the message from the last error that occured.


All times are GMT -5. The time now is 01:55 AM.