From: Nikita Popov Date: Sat, 15 Oct 2016 21:03:03 +0000 (+0200) Subject: Normalize preg_replace_callback() return value X-Git-Tag: php-7.1.0RC4~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1fc1fb9376f22693b610961a097f6d0ff6dc484;p=php Normalize preg_replace_callback() return value One particular error case was returning the argument without casting to string. --- diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ef9569b860..53e122c82b 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1584,7 +1584,7 @@ static PHP_FUNCTION(preg_replace_callback) if (!zend_is_callable(replace, 0, &callback_name)) { php_error_docref(NULL, E_WARNING, "Requires argument 2, '%s', to be a valid callback", ZSTR_VAL(callback_name)); zend_string_release(callback_name); - ZVAL_COPY(return_value, subject); + ZVAL_STR(return_value, zval_get_string(subject)); return; } zend_string_release(callback_name); diff --git a/ext/pcre/tests/preg_replace_callback3.phpt b/ext/pcre/tests/preg_replace_callback3.phpt index 6484c074fe..fc3218b9e7 100644 --- a/ext/pcre/tests/preg_replace_callback3.phpt +++ b/ext/pcre/tests/preg_replace_callback3.phpt @@ -28,13 +28,13 @@ Warning: preg_replace_callback() expects at least 3 parameters, 2 given in %s on NULL Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d -int(3) +string(1) "3" Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d -int(3) +string(1) "3" Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d -int(3) +string(1) "3" Warning: preg_replace_callback() expects parameter 4 to be integer, string given in %s on line %d NULL