diff options
Diffstat (limited to 'ext/pcre')
-rw-r--r-- | ext/pcre/php_pcre.c | 5 | ||||
-rw-r--r-- | ext/pcre/tests/preg_replace_error1.phpt | 9 | ||||
-rw-r--r-- | ext/pcre/tests/preg_replace_error2.phpt | 10 |
3 files changed, 18 insertions, 6 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 05f8d9f817..46794fe1d1 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1529,6 +1529,11 @@ PHPAPI zend_string *php_pcre_replace(zend_string *regex, pcre_cache_entry *pce; /* Compiled regular expression */ zend_string *result; /* Function result */ + /* Abort on pending exception, e.g. thrown from __toString(). */ + if (UNEXPECTED(EG(exception))) { + return NULL; + } + /* Compile regex or get it from cache. */ if ((pce = pcre_get_compiled_regex_cache(regex)) == NULL) { return NULL; diff --git a/ext/pcre/tests/preg_replace_error1.phpt b/ext/pcre/tests/preg_replace_error1.phpt index 8e20108b88..780556956a 100644 --- a/ext/pcre/tests/preg_replace_error1.phpt +++ b/ext/pcre/tests/preg_replace_error1.phpt @@ -24,7 +24,11 @@ foreach($regex_array as $regex_value) { var_dump(preg_replace($regex_value, $replace, $subject)); } $regex_value = new stdclass(); //Object -var_dump(preg_replace($regex_value, $replace, $subject)); +try { + var_dump(preg_replace($regex_value, $replace, $subject)); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} ?> --EXPECTF-- *** Testing preg_replace() : error conditions*** @@ -54,5 +58,4 @@ string(1) "a" Arg value is /[a-zA-Z]/ string(1) "1" - -Recoverable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error1.php on line %d +Object of class stdClass could not be converted to string diff --git a/ext/pcre/tests/preg_replace_error2.phpt b/ext/pcre/tests/preg_replace_error2.phpt index 8c826587ea..a334b2fefd 100644 --- a/ext/pcre/tests/preg_replace_error2.phpt +++ b/ext/pcre/tests/preg_replace_error2.phpt @@ -19,7 +19,11 @@ foreach($replace as $value) { var_dump(preg_replace($regex, $value, $subject)); } $value = new stdclass(); //Object -var_dump(preg_replace($regex, $value, $subject)); +try { + var_dump(preg_replace($regex, $value, $subject)); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} echo "Done"; ?> --EXPECTF-- @@ -32,5 +36,5 @@ Arg value is: Array Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace_error2.php on line %d bool(false) - -Recoverable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error2.php on line %d +Object of class stdClass could not be converted to string +Done |