]> granicus.if.org Git - php/commitdiff
Fixed bug #32993 (implemented Iterator function current() don't throw exception)
authorDmitry Stogov <dmitry@php.net>
Mon, 6 Jun 2005 08:24:05 +0000 (08:24 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 6 Jun 2005 08:24:05 +0000 (08:24 +0000)
NEWS
Zend/tests/bug32993.phpt [new file with mode: 0755]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/NEWS b/NEWS
index 7392e0567cd32b7308e4b9cf03392398b281ef97..d7e1a520caa114f94b72e54b3a774542188fecc6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -120,6 +120,8 @@ PHP                                                                        NEWS
 - Fixed bug with $HTTP_RAW_POST_DATA not getting set. (Brian)
 - Fixed bug in mysql::client_version(). (Georg)
 - Fixed ZTS destruction. (Marcus)
+- Fixed bug #32993 (implemented Iterator function current() don't throw
+  exception). (Dmitry)
 - Fixed bug #32924 (file included with "auto_prepend_file" can be included
   with require_once() or include_once()). (Stas)
 - Fixed bug #32833 (Invalid opcode). (Dmitry)
diff --git a/Zend/tests/bug32993.phpt b/Zend/tests/bug32993.phpt
new file mode 100755 (executable)
index 0000000..88fb023
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #32993 (implemented Iterator function current() don't throw exception)
+--FILE--
+<?php
+class Test implements Iterator {
+
+    public $arr = array();
+
+    public function rewind()    { return reset($this->arr); }
+    public function current()   { throw new Exception(); }
+    public function key()       { return key($this->arr); }
+    public function next()      { return next($this->arr); }
+    public function valid()     { return (current($this->arr) !== false); }
+}
+
+$t = new Test();
+$t->arr =  array(1, 2, 3);
+
+try {
+    foreach ($t as $v) {
+        echo "$v\n";
+    }
+} catch (Exception $e) {
+    ; // handle exception
+}
+echo "ok\n";
+?>
+--EXPECT--
+ok
index c5a5e032ae734c7d3feb7eb80ed53a9bbf7ca5f0..01610c20270229efe8ee1c12f68f94f1f7893d3f 100644 (file)
@@ -3110,13 +3110,13 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY)
                                ZEND_VM_CONTINUE_JMP();
                        }
                        iter->funcs->get_current_data(iter, &value TSRMLS_CC);
+                       if (EG(exception)) {
+                               array->refcount--;
+                               zval_ptr_dtor(&array);
+                               ZEND_VM_NEXT_OPCODE();
+                       }
                        if (!value) {
                                /* failure in get_current_data */
-                               if (EG(exception)) {
-                                       array->refcount--;
-                                       zval_ptr_dtor(&array);
-                                       ZEND_VM_NEXT_OPCODE();
-                               }
                                ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num);
                                ZEND_VM_CONTINUE_JMP();
                        }
index 173b5f120f6084f7add6fb58efc149105b7fa110..7b71bcd9d41aa4ce04be486ebe74e836cccb1146 100644 (file)
@@ -7667,13 +7667,13 @@ static int ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                                ZEND_VM_CONTINUE_JMP();
                        }
                        iter->funcs->get_current_data(iter, &value TSRMLS_CC);
+                       if (EG(exception)) {
+                               array->refcount--;
+                               zval_ptr_dtor(&array);
+                               ZEND_VM_NEXT_OPCODE();
+                       }
                        if (!value) {
                                /* failure in get_current_data */
-                               if (EG(exception)) {
-                                       array->refcount--;
-                                       zval_ptr_dtor(&array);
-                                       ZEND_VM_NEXT_OPCODE();
-                               }
                                ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num);
                                ZEND_VM_CONTINUE_JMP();
                        }
@@ -32793,13 +32793,13 @@ static int ZEND_FE_FETCH_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                                ZEND_VM_CONTINUE_JMP();
                        }
                        iter->funcs->get_current_data(iter, &value TSRMLS_CC);
+                       if (EG(exception)) {
+                               array->refcount--;
+                               zval_ptr_dtor(&array);
+                               ZEND_VM_NEXT_OPCODE();
+                       }
                        if (!value) {
                                /* failure in get_current_data */
-                               if (EG(exception)) {
-                                       array->refcount--;
-                                       zval_ptr_dtor(&array);
-                                       ZEND_VM_NEXT_OPCODE();
-                               }
                                ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num);
                                ZEND_VM_CONTINUE_JMP();
                        }