diff options
| author | Hannes Magnusson <bjori@php.net> | 2011-09-12 13:21:57 +0000 | 
|---|---|---|
| committer | Hannes Magnusson <bjori@php.net> | 2011-09-12 13:21:57 +0000 | 
| commit | 75c4d6f888feb21d1a9c8f4971c099c54629ca58 (patch) | |
| tree | 780f6f270471795768bb4e935fba62cd710bf6af | |
| parent | c4de2c86549c4f6fb5f7380c976444cdffd8eda3 (diff) | |
| download | php-git-75c4d6f888feb21d1a9c8f4971c099c54629ca58.tar.gz | |
Allow replacement to be any scalar value
| -rwxr-xr-x | ext/spl/spl_iterators.c | 12 | 
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 08650a0b60..afaa9cb9aa 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -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);  	}  | 
