Error Handling – Display Errors

To output error logs to file, “log_errors” must be “On” in php.ini.

if($debug_mode == true){
	error_reporting(E_ALL);
	ini_set('display_errors',1);
	ini_set('display_startup_errors',1);
	ini_set('log_errors',1);
}
error_reporting(E_ALL);
set_error_handler('error_handler');

function error_handler($no, $msg, $filename, $line){
	$p = 'error_log.txt';
	$handle = fopen($p, 'w+');
	fwrite($handle, 'File name:' . $filename . PHP_EOL);
	fwrite($handle, 'Line:' . $line . PHP_EOL);
	fwrite($handle, 'Msg:' . $msg . PHP_EOL);

	echo $line . ": " . $msg;
	exit();
}

//trigger_error('cat:' . $cat, E_USER_ERROR);

try{
	move_uploaded_file($this->file["tmp_name"], $new_file);
	//throw new Exception('Custom error');
}catch(Exception $ex){
	echo 'Message: ' . $ex->getMessage() . '<br/>';
	echo 'Code: ' . $ex->getCode() . '<br/>';
	echo 'File: ' . $ex->getFile() . '<br/>';
	echo 'Line: ' . $ex->getLine() . '<br/>';
}

Enable Error Display in .htaccess

php_flag display_errors 1

Reference: