]> granicus.if.org Git - php/commitdiff
Check for exception after calling count_values()
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 17 Sep 2019 11:13:44 +0000 (13:13 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 17 Sep 2019 11:13:44 +0000 (13:13 +0200)
To avoid a duplicate error if count_values() throws.

Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/ffi/tests/008.phpt
ext/standard/array.c

index c33b4f1b69e10771ee3754bb9823869e7606e086..2d8fe24fbc082bd0da7df3f5f3994c64fa1f14b0 100644 (file)
@@ -8606,6 +8606,10 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED)
                                if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
                                        break;
                                }
+                               if (UNEXPECTED(EG(exception))) {
+                                       count = 0;
+                                       break;
+                               }
                        }
 
                        /* if not and the object implements Countable we call its count() method */
index a657e020890ba7fd9e4413697a2d9118a5b695f7..5927f7958017823cdc538f0b328b4728a4fbb3e0 100644 (file)
@@ -9634,6 +9634,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
                                if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
                                        break;
                                }
+                               if (UNEXPECTED(EG(exception))) {
+                                       count = 0;
+                                       break;
+                               }
                        }
 
                        /* if not and the object implements Countable we call its count() method */
@@ -16771,6 +16775,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
                                if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
                                        break;
                                }
+                               if (UNEXPECTED(EG(exception))) {
+                                       count = 0;
+                                       break;
+                               }
                        }
 
                        /* if not and the object implements Countable we call its count() method */
@@ -46640,6 +46648,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
                                if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
                                        break;
                                }
+                               if (UNEXPECTED(EG(exception))) {
+                                       count = 0;
+                                       break;
+                               }
                        }
 
                        /* if not and the object implements Countable we call its count() method */
index 626b2890ce2140d2b66524023116120261fc661c..fa3991abeea727108c70c47dd50b4c5e19d6f306 100644 (file)
@@ -16,7 +16,7 @@ foreach ($a as $key => $val) {
 
 $a = FFI::new("struct {int x,y;}");
 try {
-       var_dump(@count($a));
+       var_dump(count($a));
 } catch (Throwable $e) {
        echo get_class($e) . ": " . $e->getMessage()."\n";
 }
index 73b3d35a08132758f5638a6895cbd69772184154..d44e5d50e741b6ac61bfffa3641f226365e8940c 100644 (file)
@@ -794,6 +794,9 @@ PHP_FUNCTION(count)
                                if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value))) {
                                        return;
                                }
+                               if (EG(exception)) {
+                                       return;
+                               }
                        }
                        /* if not and the object implements Countable we call its count() method */
                        if (instanceof_function(Z_OBJCE_P(array), zend_ce_countable)) {