Skip to content

Commit d266ba4

Browse files
committed
Check for exception after calling count_values()
To avoid a duplicate error if count_values() throws.
1 parent ce25fa0 commit d266ba4

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Zend/zend_vm_def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8606,6 +8606,10 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED)
86068606
if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
86078607
break;
86088608
}
8609+
if (UNEXPECTED(EG(exception))) {
8610+
count = 0;
8611+
break;
8612+
}
86098613
}
86108614

86118615
/* if not and the object implements Countable we call its count() method */

Zend/zend_vm_execute.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9634,6 +9634,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
96349634
if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
96359635
break;
96369636
}
9637+
if (UNEXPECTED(EG(exception))) {
9638+
count = 0;
9639+
break;
9640+
}
96379641
}
96389642

96399643
/* 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
1677116775
if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
1677216776
break;
1677316777
}
16778+
if (UNEXPECTED(EG(exception))) {
16779+
count = 0;
16780+
break;
16781+
}
1677416782
}
1677516783

1677616784
/* 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
4664046648
if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) {
4664146649
break;
4664246650
}
46651+
if (UNEXPECTED(EG(exception))) {
46652+
count = 0;
46653+
break;
46654+
}
4664346655
}
4664446656

4664546657
/* if not and the object implements Countable we call its count() method */

ext/ffi/tests/008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ foreach ($a as $key => $val) {
1616

1717
$a = FFI::new("struct {int x,y;}");
1818
try {
19-
var_dump(@count($a));
19+
var_dump(count($a));
2020
} catch (Throwable $e) {
2121
echo get_class($e) . ": " . $e->getMessage()."\n";
2222
}

ext/standard/array.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,9 @@ PHP_FUNCTION(count)
794794
if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value))) {
795795
return;
796796
}
797+
if (EG(exception)) {
798+
return;
799+
}
797800
}
798801
/* if not and the object implements Countable we call its count() method */
799802
if (instanceof_function(Z_OBJCE_P(array), zend_ce_countable)) {

0 commit comments

Comments
 (0)