<?php
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
$namespace = 'ajf\ErrorExceptions\Dynamic';
$className = implode('', explode(' ', ucwords($errstr)));
$fullClassName = $namespace . '\\' . $className;
if (!class_exists($fullClassName)) {
eval("namespace $namespace { class $className extends \ErrorException {} }");
}
throw new $fullClassName($errstr, 0, $errno, $errfile, $errline);
});
try {
$foo = 1/0;
} catch (ajf\ErrorExceptions\Dynamic\DivisionByZero $e) {
echo "ba-da-bing, ba-da-boom: I caught a $e!\n";
}
try {
$repent = sin("123abc");
} catch (ajf\ErrorExceptions\Dynamic\ANonWellFormedNumericStringEncountered $e) {
echo "praise be to zend_is_numeric_string_ex: $e"
}
- Output for 5.5.24 - 5.5.31, 5.6.8 - 5.6.17, 7.0.0 - 7.0.2
- Parse error: syntax error, unexpected '}', expecting ',' or ';' in /in/rvMXg on line 24
Process exited with code 255.
preferences:
166.36 ms | 941 KiB | 29 Q