Skip to content

Instantly share code, notes, and snippets.

@juzna
Created September 3, 2012 21:56
Show Gist options
  • Save juzna/3613877 to your computer and use it in GitHub Desktop.
Save juzna/3613877 to your computer and use it in GitHub Desktop.
PHP WTF? Error handler is not called, when display_errors=On
<?php
/**
* WTF? Error handler is not called, when display_errors=On
*/
function _errorHandler($severity, $message, $file, $line, $context) {
$GLOBALS['err'] = func_get_args();
// echo "Error ($severity) $message in $file:$line\n";
}
set_error_handler('_errorHandler');
// display_errors = Off, works fine
{
ini_set('display_errors', 0);
// Calls error handler, fine
$err = NULL;
$tmp = substr(new stdClass(), 1, 1);
var_dump($err[0], $err[1]);
// Calls error handler, fine
$err = NULL;
$tmp = json_encode(array("bad utf\xFF"));
var_dump($err[0], $err[1]);
}
// display_errors = On, WTF???
{
ini_set('display_errors', 1);
// Calls error handler, fine
$err = NULL;
$tmp = substr(new stdClass(), 1, 1);
var_dump($err[0], $err[1]);
// Does NOT call error handler, WTF???
$err = NULL;
$tmp = json_encode(array("bad utf\xFF"));
var_dump($err[0], $err[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment