PHP 8 has a native function to retrieve the actual error message, so these helper functions are no longer necessary. https://www.php.net/preg_last_error_msg <?php preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar'); if (preg_last_error() !== PREG_NO_ERROR) { echo preg_last_error_msg(); // Prints "Backtrack limit exhausted" } ?>