Skip to content

Commit a5656e7

Browse files
committed
Move mode checks into ZPP branches
1 parent dbf37b4 commit a5656e7

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
@@ -758,11 +758,6 @@ PHP_FUNCTION(count)
758758
zend_long mode = COUNT_NORMAL;
759759
zval *countable;
760760

761-
if (mode != COUNT_NORMAL && mode != COUNT_RECURSIVE) {
762-
zend_value_error("Mode value is invalid");
763-
RETURN_THROWS();
764-
}
765-
766761
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "h!|l", &array, &mode) == SUCCESS) {
767762
if (array == NULL) {
768763
/* Intentionally not converted to an exception */
@@ -772,19 +767,27 @@ PHP_FUNCTION(count)
772767

773768
zend_long count;
774769

775-
if (mode == COUNT_RECURSIVE) {
770+
if (mode == COUNT_NORMAL) {
771+
count = zend_array_count(array);
772+
} else if (mode == COUNT_RECURSIVE) {
776773
count = php_count_recursive(array);
777774
} else {
778-
count = zend_array_count(array);
775+
zend_value_error("Mode value is invalid");
776+
RETURN_THROWS();
779777
}
780778
RETURN_LONG(count);
781779
}
782780

783781
/* Remove possibility to specify $mode when passing object? */
784-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O|l",
785-
&countable, zend_ce_countable, &mode) == SUCCESS) {
786-
zval retval;
787-
/* First, we check if the count handler is defined */
782+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "o|l",
783+
&countable, &mode) == SUCCESS) {
784+
785+
if (mode != COUNT_NORMAL && mode != COUNT_RECURSIVE) {
786+
zend_value_error("Mode value is invalid");
787+
RETURN_THROWS();
788+
}
789+
790+
/* First, check if the handler is defined as it is faster */
788791
if (Z_OBJ_HT_P(countable)->count_elements) {
789792
RETVAL_LONG(1);
790793
if (SUCCESS == Z_OBJ_HT(*countable)->count_elements(Z_OBJ_P(countable), &Z_LVAL_P(return_value))) {

0 commit comments

Comments
 (0)