Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

[PHP] A Simple Error Function For Everyday Use...

DZone's Guide to

[PHP] A Simple Error Function For Everyday Use...

·
Free Resource
... 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();
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}