[Techno WeBlog] PHP Custom Error Messages

0 views
Skip to first unread message

Jansan John

unread,
Jun 8, 2007, 11:42:40 PM6/8/07
to cod...@googlegroups.com

This is a continuation to my post PHP Magic Constants.
Here I would like to demonstrate a real time example of magic constants.

I am going to write a user function for generating a user-level error/warning/notice message.

function myErrorFunction($error_message,$line,$file)
{
if($error_message!='')
{
$error_string = "User Error : {$error_message} in
{$file} on line number {$line}";
echo $error_string;
die();
}

}

myErrorFunction('test error message',__LINE__,__FILE__);


Now, you can call this function any where in your
script. It should print the error message as follows.

User Error : test error message in H:\test\ccodlib\test.php on line number 12


In the above function,
• die() is a portable way of causing the program to crash.
• __FILE__ is replaced (during compilation) with the name of the file containing the code (as a string).
• __LINE__ is replaced (during compilation) with the current line number (as an integer constant).

------------------

you can also achieve the above functionality by using the built in function "Trigger_error()" provided by PHP.

--
Posted By Jansan John to Techno WeBlog at 6/08/2007 08:02:00 AM
Reply all
Reply to author
Forward
0 new messages