While I’m trying to handle WARNING messages, I’m getting error for global variable/array (on last print_r line):
Notice: Undefined variable: errors in……..
I tried to declare $errors outside of function as well but same problem.
Thanks
My code:
set_error_handler('validation_error_handler', E_WARNING);
function validation_error_handler($error_no, $error_message)
{
global $errors;
$errors[] = $error_message;
}
echo '<pre>'; print_r($errors); echo '</pre>';
You need to declare
$errorsas an array first:Update:
This will print
Make sure your error/warning occurs before you
print_r($errors);