LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2004, 08:23 AM   #1
id10t
Member
 
Registered: Dec 2003
Location: Minnesota
Distribution: Slackware 9.1
Posts: 63

Rep: Reputation: 15
Question 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

Last edited by id10t; 05-27-2004 at 08:24 AM.
 
Old 05-27-2004, 10:21 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
http://fr2.php.net/manual/en/ref.errorfunc.php

edit : found the good url

Last edited by keefaz; 05-27-2004 at 10:22 AM.
 
Old 05-27-2004, 12:18 PM   #3
id10t
Member
 
Registered: Dec 2003
Location: Minnesota
Distribution: Slackware 9.1
Posts: 63

Original Poster
Rep: Reputation: 15
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;
 
Old 05-27-2004, 12:19 PM   #4
id10t
Member
 
Registered: Dec 2003
Location: Minnesota
Distribution: Slackware 9.1
Posts: 63

Original Poster
Rep: Reputation: 15
Now that I think of it, a function that would grab the current line and file-name/path would be pretty sweet too.
 
Old 05-27-2004, 04:12 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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
 
Old 05-30-2004, 06:24 PM   #6
id10t
Member
 
Registered: Dec 2003
Location: Minnesota
Distribution: Slackware 9.1
Posts: 63

Original Poster
Rep: Reputation: 15
__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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using return in recursive function hubabuba Programming 9 10-10-2005 09:59 AM
can a function return a string? hubabuba Programming 13 03-06-2005 02:51 PM
Fatal Error - Call to undefined function : pg_pconnect() in filename.php on line xx mwpeng Linux - Newbie 1 02-26-2005 08:57 AM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM
File Permission Error in PHP fopen() function tuka Linux - Software 2 08-12-2003 08:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration