This is really short, but it saved the day, okay?
You're migrating from PHP 5 to PHP 7 - about time, isn't it? - and you're replacing $php_errormsg
with error_clear_last()
and error_get_last()
, but you realize the newer functions are PHP 7 only, and you can't deploy the updated code to your
thousands of servers all at once, because you live in the real world.
This particular application has to run under both PHP 5 and PHP 7.
$php_errormsg = '';
if (function_exists('error_clear_last')) {
error_clear_last();
}
...
if (function_exists('error_get_last')) {
if (! is_null(error_get_last())) {
$php_errormsg = error_get_last()['message'];
}
}
Now, you can at least use $php_errormsg
variable in your code, as before. Under PHP 7, you can make also use of the other
indexes in the array returned; namely, [type]
, [file]
, and [line]
.