Skip to content

Commit 0d10903

Browse files
committed
Move mode checks into ZPP branches
1 parent dcc3e68 commit 0d10903

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

ext/standard/array.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,6 @@ PHP_FUNCTION(count)
697697
zend_long mode = COUNT_NORMAL;
698698
zval *countable;
699699

700-
if (mode != COUNT_NORMAL && mode != COUNT_RECURSIVE) {
701-
zend_value_error("Mode value is invalid");
702-
RETURN_THROWS();
703-
}
704-
705700
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "h!|l", &array, &mode) == SUCCESS) {
706701
if (array == NULL) {
707702
/* Intentionally not converted to an exception */
@@ -711,19 +706,27 @@ PHP_FUNCTION(count)
711706

712707
zend_long count;
713708

714-
if (mode == COUNT_RECURSIVE) {
709+
if (mode == COUNT_NORMAL) {
710+
count = zend_array_count(array);
711+
} else if (mode == COUNT_RECURSIVE) {
715712
count = php_count_recursive(array);
716713
} else {
717-
count = zend_array_count(array);
714+
zend_value_error("Mode value is invalid");
715+
RETURN_THROWS();
718716
}
719717
RETURN_LONG(count);
720718
}
721719

722720
/* Remove possibility to specify $mode when passing object? */
723-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O|l",
724-
&countable, zend_ce_countable, &mode) == SUCCESS) {
725-
zval retval;
726-
/* First, we check if the count handler is defined */
721+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "o|l",
722+
&countable, &mode) == SUCCESS) {
723+
724+
if (mode != COUNT_NORMAL && mode != COUNT_RECURSIVE) {
725+
zend_value_error("Mode value is invalid");
726+
RETURN_THROWS();
727+
}
728+
729+
/* First, check if the handler is defined as it is faster */
727730
if (Z_OBJ_HT_P(countable)->count_elements) {
728731
RETVAL_LONG(1);
729732
if (SUCCESS == Z_OBJ_HT(*countable)->count_elements(Z_OBJ_P(countable), &Z_LVAL_P(return_value))) {

0 commit comments

Comments
 (0)