mirror of
https://github.com/php/php-src.git
synced 2024-12-05 07:46:06 +08:00
Allow replacement to be any scalar value
This commit is contained in:
parent
c4de2c8654
commit
75c4d6f888
@ -1868,7 +1868,7 @@ SPL_METHOD(RegexIterator, accept)
|
||||
spl_dual_it_object *intern;
|
||||
char *subject, tmp[32], *result;
|
||||
int subject_len, use_copy, count = 0, result_len;
|
||||
zval subject_copy, zcount, *replacement;
|
||||
zval subject_copy, zcount, *replacement, tmp_replacement;
|
||||
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
return;
|
||||
@ -1937,6 +1937,12 @@ SPL_METHOD(RegexIterator, accept)
|
||||
|
||||
case REGIT_MODE_REPLACE:
|
||||
replacement = zend_read_property(intern->std.ce, getThis(), "replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
|
||||
if (Z_TYPE_P(replacement) != IS_STRING) {
|
||||
tmp_replacement = *replacement;
|
||||
zval_copy_ctor(&tmp_replacement);
|
||||
convert_to_string(&tmp_replacement);
|
||||
replacement = &tmp_replacement;
|
||||
}
|
||||
result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC);
|
||||
|
||||
if (intern->u.regex.flags & REGIT_USE_KEY) {
|
||||
@ -1951,6 +1957,10 @@ SPL_METHOD(RegexIterator, accept)
|
||||
MAKE_STD_ZVAL(intern->current.data);
|
||||
ZVAL_STRINGL(intern->current.data, result, result_len, 0);
|
||||
}
|
||||
|
||||
if (replacement == &tmp_replacement) {
|
||||
zval_dtor(replacement);
|
||||
}
|
||||
RETVAL_BOOL(count > 0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user