]> granicus.if.org Git - php/commitdiff
Fixed bug #72051 (The reference in CallbackFilterIterator doesn't work as expected)
authorXinchen Hui <laruence@gmail.com>
Tue, 19 Apr 2016 02:59:10 +0000 (10:59 +0800)
committerXinchen Hui <laruence@gmail.com>
Tue, 19 Apr 2016 02:59:10 +0000 (10:59 +0800)
NEWS
ext/spl/spl_iterators.c
ext/spl/tests/bug72051.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 97b192c5f376f59999e43717c3d9496033b8626c..440ce4e2f4eba5aa0465752fee1fc3dc9d0f34d5 100644 (file)
--- 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)
 
index 8ff342701176066507f69f8437d35ce46c86f4b4..6a0049733fa6687e2d9190caee0eea28bd657bad 100644 (file)
@@ -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(&params[1], &intern->current.key);
        ZVAL_COPY_VALUE(&params[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, &params[0]);
+       ZVAL_COPY_VALUE(&intern->current.key, &params[1]);
 }
 /* }}} */
 
diff --git a/ext/spl/tests/bug72051.phpt b/ext/spl/tests/bug72051.phpt
new file mode 100644 (file)
index 0000000..1dfc056
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Bug #72051 (The reference in CallbackFilterIterator doesn't work as expected)
+--FILE--
+<?php
+
+$data = [
+       [1,2]
+];
+
+$callbackTest = new CallbackFilterIterator(new ArrayIterator($data), function (&$current) {
+       $current['message'] = 'Test message';
+       return true;
+});
+
+$callbackTest->rewind();
+$data = $callbackTest->current();
+$callbackTest->next();
+print_r($data);
+?>
+--EXPECT--
+Array
+(
+    [0] => 1
+    [1] => 2
+    [message] => Test message
+)