DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
[PHP] A Simple Error Function For Everyday Use...
... It uses the php function "error_log".
define("PATH_LOG","./log/");
function error($line,$method,$class,$system_error,$user_error = "",$date = "",$log = true,$show = true) {
if (empty($date)) {
$date = date('r');
}
if (empty($user_error)) {
$user_error = $system_error;
}
$error = "$date - $method at $line - $system_error\n";
if ($log == true) {
error_log($error,3,PATH_LOG."$class.log");
}
if ($show == true) {
echo "<div class=\"error\">$user_error</div>";
}
return true;
}
//Example
class Test {
private showError true;
public function __construct() {
$test = false;
if ($test === false) {
error(__LINE__,__METHOD__,__CLASS__,"sys error blub","There are internal problems. Sorry for that.","",true,$this->showError);
}
}
}
$test = new Test();





