@@ -52,17 +52,6 @@ struct _pcre_cache_entry {
5252 uint32_t refcount ;
5353};
5454
55- enum {
56- PHP_PCRE_NO_ERROR = 0 ,
57- PHP_PCRE_INTERNAL_ERROR ,
58- PHP_PCRE_BACKTRACK_LIMIT_ERROR ,
59- PHP_PCRE_RECURSION_LIMIT_ERROR ,
60- PHP_PCRE_BAD_UTF8_ERROR ,
61- PHP_PCRE_BAD_UTF8_OFFSET_ERROR ,
62- PHP_PCRE_JIT_STACKLIMIT_ERROR
63- };
64-
65-
6655PHPAPI ZEND_DECLARE_MODULE_GLOBALS (pcre )
6756
6857#ifdef HAVE_PCRE_JIT_SUPPORT
@@ -138,6 +127,33 @@ static void pcre_handle_exec_error(int pcre_code) /* {{{ */
138127}
139128/* }}} */
140129
130+ static const char * php_pcre_get_error_msg (php_pcre_error_code error_code ) /* {{{ */
131+ {
132+ switch (error_code ) {
133+ case PHP_PCRE_NO_ERROR :
134+ return "No error" ;
135+ case PHP_PCRE_INTERNAL_ERROR :
136+ return "Internal error" ;
137+ case PHP_PCRE_BAD_UTF8_ERROR :
138+ return "Malformed UTF-8 characters, possibly incorrectly encoded" ;
139+ case PHP_PCRE_BAD_UTF8_OFFSET_ERROR :
140+ return "The offset did not correspond to the beginning of a valid UTF-8 code point" ;
141+ case PHP_PCRE_BACKTRACK_LIMIT_ERROR :
142+ return "Backtrack limit exhausted" ;
143+ case PHP_PCRE_RECURSION_LIMIT_ERROR :
144+ return "Recursion limit exhausted" ;
145+
146+ #ifdef HAVE_PCRE_JIT_SUPPORT
147+ case PHP_PCRE_JIT_STACKLIMIT_ERROR :
148+ return "JIT stack limit exhausted" ;
149+ #endif
150+
151+ default :
152+ return "Unknown error" ;
153+ }
154+ }
155+ /* }}} */
156+
141157static void php_free_pcre_cache (zval * data ) /* {{{ */
142158{
143159 pcre_cache_entry * pce = (pcre_cache_entry * ) Z_PTR_P (data );
@@ -2957,6 +2973,16 @@ static PHP_FUNCTION(preg_last_error)
29572973}
29582974/* }}} */
29592975
2976+ /* {{{ proto string preg_last_error_msg()
2977+ Returns the error message of the last regexp execution. */
2978+ static PHP_FUNCTION (preg_last_error_msg )
2979+ {
2980+ ZEND_PARSE_PARAMETERS_NONE ();
2981+
2982+ RETURN_STRING (php_pcre_get_error_msg (PCRE_G (error_code )));
2983+ }
2984+ /* }}} */
2985+
29602986/* {{{ module definition structures */
29612987
29622988static const zend_function_entry pcre_functions [] = {
@@ -2970,6 +2996,7 @@ static const zend_function_entry pcre_functions[] = {
29702996 PHP_FE (preg_quote , arginfo_preg_quote )
29712997 PHP_FE (preg_grep , arginfo_preg_grep )
29722998 PHP_FE (preg_last_error , arginfo_preg_last_error )
2999+ PHP_FE (preg_last_error_msg , arginfo_preg_last_error_msg )
29733000 PHP_FE_END
29743001};
29753002
0 commit comments