Here is a correction to one of the previous "get error message" snippets. It filters out the non-error codes which stops "Warning: array_flip(): Can only flip STRING and INTEGER values!" from being emitted due to ["PCRE_JIT_SUPPORT"]=>bool(true):
<?php
echo array_flip(array_filter(get_defined_constants(true)['pcre'], function ($value) {
return substr($value, -6) === '_ERROR';
}, ARRAY_FILTER_USE_KEY))[preg_last_error()];