» tagged pages
» logout
PHP
Return to PHP Code Snippets

[PHP] A simple error function for everyday use...

Tags Applied to this Entry

1 person has tagged this page:
... 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 "
$user_error
";
}

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();
Username:
Password:
(or Cancel)