Skip to content

Commit e757ec4

Browse files
committed
Merge branch 'PHP-7.0'
* PHP-7.0: Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as expected)
2 parents f017755 + 5ea2b36 commit e757ec4

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

ext/spl/spl_iterators.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,6 @@ SPL_METHOD(CallbackFilterIterator, accept)
19981998
zend_fcall_info *fci = &intern->u.cbfilter->fci;
19991999
zend_fcall_info_cache *fcc = &intern->u.cbfilter->fcc;
20002000
zval params[3];
2001-
zval result;
20022001

20032002
if (zend_parse_parameters_none() == FAILURE) {
20042003
return;
@@ -2012,19 +2011,22 @@ SPL_METHOD(CallbackFilterIterator, accept)
20122011
ZVAL_COPY_VALUE(&params[1], &intern->current.key);
20132012
ZVAL_COPY_VALUE(&params[2], &intern->inner.zobject);
20142013

2015-
fci->retval = &result;
2014+
fci->retval = return_value;
20162015
fci->param_count = 3;
20172016
fci->params = params;
20182017
fci->no_separation = 0;
20192018

2020-
if (zend_call_function(fci, fcc) != SUCCESS || Z_TYPE(result) == IS_UNDEF) {
2019+
if (zend_call_function(fci, fcc) != SUCCESS || Z_ISUNDEF_P(return_value)) {
20212020
RETURN_FALSE;
20222021
}
2022+
20232023
if (EG(exception)) {
2024-
return;
2024+
RETURN_NULL();
20252025
}
20262026

2027-
RETURN_ZVAL(&result, 1, 1);
2027+
/* zend_call_function may change args to IS_REF */
2028+
ZVAL_COPY_VALUE(&intern->current.data, &params[0]);
2029+
ZVAL_COPY_VALUE(&intern->current.key, &params[1]);
20282030
}
20292031
/* }}} */
20302032

ext/spl/tests/bug72051.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #72051 (The reference in CallbackFilterIterator doesn't work as expected)
3+
--FILE--
4+
<?php
5+
6+
$data = [
7+
[1,2]
8+
];
9+
10+
$callbackTest = new CallbackFilterIterator(new ArrayIterator($data), function (&$current) {
11+
$current['message'] = 'Test message';
12+
return true;
13+
});
14+
15+
$callbackTest->rewind();
16+
$data = $callbackTest->current();
17+
$callbackTest->next();
18+
print_r($data);
19+
?>
20+
--EXPECT--
21+
Array
22+
(
23+
[0] => 1
24+
[1] => 2
25+
[message] => Test message
26+
)

0 commit comments

Comments
 (0)