@@ -9263,21 +9263,21 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
9263
9263
count = zend_array_count(Z_ARRVAL_P(op1));
9264
9264
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
9265
9265
zend_object *zobj = Z_OBJ_P(op1);
9266
- /* if the object implements Countable we call its count() method */
9267
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9268
- zval retval;
9269
-
9270
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9271
- count = zval_get_long(&retval);
9272
- zval_ptr_dtor(&retval);
9273
- /* Else if the object has a count handler defined */
9274
- } else if (zobj->handlers->count_elements) {
9266
+ /* First, check if the handler is defined as it is faster */
9267
+ if (zobj->handlers->count_elements) {
9275
9268
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
9276
9269
zend_type_error("Parameter must be an array or an object that implements Countable");
9277
9270
}
9278
9271
if (UNEXPECTED(EG(exception))) {
9279
9272
count = 0;
9280
9273
}
9274
+ /* Otherwise check if the object implements Countable and call its count() method */
9275
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9276
+ zval retval;
9277
+
9278
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9279
+ count = zval_get_long(&retval);
9280
+ zval_ptr_dtor(&retval);
9281
9281
} else {
9282
9282
zend_type_error("Parameter must be an array or an object that implements Countable");
9283
9283
}
@@ -16278,21 +16278,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
16278
16278
count = zend_array_count(Z_ARRVAL_P(op1));
16279
16279
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
16280
16280
zend_object *zobj = Z_OBJ_P(op1);
16281
- /* if the object implements Countable we call its count() method */
16282
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16283
- zval retval;
16284
-
16285
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16286
- count = zval_get_long(&retval);
16287
- zval_ptr_dtor(&retval);
16288
- /* Else if the object has a count handler defined */
16289
- } else if (zobj->handlers->count_elements) {
16281
+ /* First, check if the handler is defined as it is faster */
16282
+ if (zobj->handlers->count_elements) {
16290
16283
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
16291
16284
zend_type_error("Parameter must be an array or an object that implements Countable");
16292
16285
}
16293
16286
if (UNEXPECTED(EG(exception))) {
16294
16287
count = 0;
16295
16288
}
16289
+ /* Otherwise check if the object implements Countable and call its count() method */
16290
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16291
+ zval retval;
16292
+
16293
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16294
+ count = zval_get_long(&retval);
16295
+ zval_ptr_dtor(&retval);
16296
16296
} else {
16297
16297
zend_type_error("Parameter must be an array or an object that implements Countable");
16298
16298
}
@@ -45068,21 +45068,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
45068
45068
count = zend_array_count(Z_ARRVAL_P(op1));
45069
45069
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
45070
45070
zend_object *zobj = Z_OBJ_P(op1);
45071
- /* if the object implements Countable we call its count() method */
45072
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
45073
- zval retval;
45074
-
45075
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
45076
- count = zval_get_long(&retval);
45077
- zval_ptr_dtor(&retval);
45078
- /* Else if the object has a count handler defined */
45079
- } else if (zobj->handlers->count_elements) {
45071
+ /* First, check if the handler is defined as it is faster */
45072
+ if (zobj->handlers->count_elements) {
45080
45073
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
45081
45074
zend_type_error("Parameter must be an array or an object that implements Countable");
45082
45075
}
45083
45076
if (UNEXPECTED(EG(exception))) {
45084
45077
count = 0;
45085
45078
}
45079
+ /* Otherwise check if the object implements Countable and call its count() method */
45080
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
45081
+ zval retval;
45082
+
45083
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
45084
+ count = zval_get_long(&retval);
45085
+ zval_ptr_dtor(&retval);
45086
45086
} else {
45087
45087
zend_type_error("Parameter must be an array or an object that implements Countable");
45088
45088
}
0 commit comments