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