For those of you looking to use your own file or line number in the error (possibly using debug_backtrace()) instead of the ones created by trigger_error(), here is a solution:
Create a custom function to handle E_USER_ERRORs that simply outputs the error type and message, while excluding the line number and file trigger_error() reports. You may also configure it to handle user warnings and notices if necessary (I did in the example below).
<?php
function error_handler($level, $message, $file, $line, $context) {
if($level === E_USER_ERROR || $level === E_USER_WARNING || $level === E_USER_NOTICE) {
echo '<strong>Error:</strong> '.$message;
return(true); }
return(false); }
function trigger_my_error($message, $level) {
$callee = next(debug_backtrace());
trigger_error($message.' in <strong>'.$callee['file'].'</strong> on line <strong>'.$callee['line'].'</strong>', $level);
}
set_error_handler('error_handler');
function abc($str) {
if(!is_string($str)) {
trigger_my_error('abc() expects parameter 1 to be a string', E_USER_ERROR);
}
}
abc('Hello world!'); abc(18); ?>
This is a pretty simple concept and I'm sure most of you know this, but for those that don't, let it serve as a good example!