use phprs::errors::{
php_error, php_error_at_line, php_set_error_handler, PhpError, PhpErrorType,
};
fn main() {
println!("=== phprs Error Handling Example ===\n");
php_set_error_handler(|error: &PhpError| {
println!(
"[Custom Handler] {}: {}",
match error.r#type {
PhpErrorType::Error => "ERROR",
PhpErrorType::Warning => "WARNING",
PhpErrorType::Notice => "NOTICE",
_ => "OTHER",
},
error.message
);
});
println!("Reporting errors:\n");
php_error(PhpErrorType::Notice, "This is a notice");
php_error(PhpErrorType::Warning, "This is a warning");
php_error(PhpErrorType::Error, "This is an error");
println!("\nError with location:");
php_error_at_line(
PhpErrorType::Parse,
"example.php",
42,
"Parse error: unexpected token",
);
println!("\nUsing default error handler:");
}