diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index d2ff9757c7d..ccd46c575d2 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -8600,6 +8600,10 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED) if (SUCCESS == zobj->handlers->count_elements(zobj, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 1bd056f73fd..1a62480bb3f 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -9560,6 +9560,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_ if (SUCCESS == zobj->handlers->count_elements(zobj, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ @@ -16689,6 +16693,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL if (SUCCESS == zobj->handlers->count_elements(zobj, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ @@ -47315,6 +47323,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z if (SUCCESS == zobj->handlers->count_elements(zobj, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ diff --git a/ext/ffi/tests/008.phpt b/ext/ffi/tests/008.phpt index 626b2890ce2..fa3991abeea 100644 --- a/ext/ffi/tests/008.phpt +++ b/ext/ffi/tests/008.phpt @@ -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"; } diff --git a/ext/standard/array.c b/ext/standard/array.c index 245eeba7d87..6634611f5e2 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -792,6 +792,9 @@ PHP_FUNCTION(count) if (SUCCESS == Z_OBJ_HT(*array)->count_elements(Z_OBJ_P(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)) {