Created
February 12, 2014 22:51
-
-
Save inelgnu/8966181 to your computer and use it in GitHub Desktop.
Handle undefined index error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
set_error_handler('undefinedIndexHandler'); | |
function undefinedIndexHandler($errno, $errstr, $errfile, $errline, $errcontext) | |
{ | |
if (!preg_match('/Undefined index/', $errstr)) { | |
return; | |
} | |
$ouput = 'Maybe you should try one of these keys : '; | |
foreach(array_keys($errcontext['a']) as $key) { | |
$ouput .= sprintf(' "%s" ', $key); | |
} | |
printf($ouput); | |
} | |
$a=['foo' => 1, 'bar' => 2, 'baz' => 3]; | |
$a['toto']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment