From: Xinchen Hui Date: Tue, 19 Apr 2016 02:59:10 +0000 (+0800) Subject: Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as expected) X-Git-Tag: php-7.0.7RC1~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7648f20de3ea31a4ee720238149af8018c0f908f;p=php Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as expected) --- diff --git a/NEWS b/NEWS index 97b192c5f3..440ce4e2f4 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,10 @@ PHP NEWS . Fixed bug #71972 (Cyclic references causing session_start(): Failed to decode session object). (Laruence) +- SPL: + . Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as + expected). (Laruence) + - SQLite3: . Fixed bug #68849 (bindValue is not using the right data type). (Anatol) diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 8ff3427011..6a0049733f 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -1998,7 +1998,6 @@ SPL_METHOD(CallbackFilterIterator, accept) zend_fcall_info *fci = &intern->u.cbfilter->fci; zend_fcall_info_cache *fcc = &intern->u.cbfilter->fcc; zval params[3]; - zval result; if (zend_parse_parameters_none() == FAILURE) { return; @@ -2012,19 +2011,22 @@ SPL_METHOD(CallbackFilterIterator, accept) ZVAL_COPY_VALUE(¶ms[1], &intern->current.key); ZVAL_COPY_VALUE(¶ms[2], &intern->inner.zobject); - fci->retval = &result; + fci->retval = return_value; fci->param_count = 3; fci->params = params; fci->no_separation = 0; - if (zend_call_function(fci, fcc) != SUCCESS || Z_TYPE(result) == IS_UNDEF) { + if (zend_call_function(fci, fcc) != SUCCESS || Z_ISUNDEF_P(return_value)) { RETURN_FALSE; } + if (EG(exception)) { - return; + RETURN_NULL(); } - RETURN_ZVAL(&result, 1, 1); + /* zend_call_function may change args to IS_REF */ + ZVAL_COPY_VALUE(&intern->current.data, ¶ms[0]); + ZVAL_COPY_VALUE(&intern->current.key, ¶ms[1]); } /* }}} */ diff --git a/ext/spl/tests/bug72051.phpt b/ext/spl/tests/bug72051.phpt new file mode 100644 index 0000000000..1dfc056d7e --- /dev/null +++ b/ext/spl/tests/bug72051.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #72051 (The reference in CallbackFilterIterator doesn't work as expected) +--FILE-- +rewind(); +$data = $callbackTest->current(); +$callbackTest->next(); +print_r($data); +?> +--EXPECT-- +Array +( + [0] => 1 + [1] => 2 + [message] => Test message +)