@@ -9231,21 +9231,21 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
9231
9231
count = zend_array_count(Z_ARRVAL_P(op1));
9232
9232
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
9233
9233
zend_object *zobj = Z_OBJ_P(op1);
9234
- /* if the object implements Countable we call its count() method */
9235
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9236
- zval retval;
9237
-
9238
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9239
- count = zval_get_long(&retval);
9240
- zval_ptr_dtor(&retval);
9241
- /* Else if the object has a count handler defined */
9242
- } else if (zobj->handlers->count_elements) {
9234
+ /* First, check if the handler is defined as it is faster */
9235
+ if (zobj->handlers->count_elements) {
9243
9236
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
9244
9237
zend_type_error("Parameter must be an array or an object that implements Countable");
9245
9238
}
9246
9239
if (UNEXPECTED(EG(exception))) {
9247
9240
count = 0;
9248
9241
}
9242
+ /* Otherwise check if the object implements Countable and call its count() method */
9243
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9244
+ zval retval;
9245
+
9246
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9247
+ count = zval_get_long(&retval);
9248
+ zval_ptr_dtor(&retval);
9249
9249
} else {
9250
9250
zend_type_error("Parameter must be an array or an object that implements Countable");
9251
9251
}
@@ -16246,21 +16246,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
16246
16246
count = zend_array_count(Z_ARRVAL_P(op1));
16247
16247
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
16248
16248
zend_object *zobj = Z_OBJ_P(op1);
16249
- /* if the object implements Countable we call its count() method */
16250
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16251
- zval retval;
16252
-
16253
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16254
- count = zval_get_long(&retval);
16255
- zval_ptr_dtor(&retval);
16256
- /* Else if the object has a count handler defined */
16257
- } else if (zobj->handlers->count_elements) {
16249
+ /* First, check if the handler is defined as it is faster */
16250
+ if (zobj->handlers->count_elements) {
16258
16251
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
16259
16252
zend_type_error("Parameter must be an array or an object that implements Countable");
16260
16253
}
16261
16254
if (UNEXPECTED(EG(exception))) {
16262
16255
count = 0;
16263
16256
}
16257
+ /* Otherwise check if the object implements Countable and call its count() method */
16258
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16259
+ zval retval;
16260
+
16261
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16262
+ count = zval_get_long(&retval);
16263
+ zval_ptr_dtor(&retval);
16264
16264
} else {
16265
16265
zend_type_error("Parameter must be an array or an object that implements Countable");
16266
16266
}
@@ -44803,21 +44803,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
44803
44803
count = zend_array_count(Z_ARRVAL_P(op1));
44804
44804
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
44805
44805
zend_object *zobj = Z_OBJ_P(op1);
44806
- /* if the object implements Countable we call its count() method */
44807
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
44808
- zval retval;
44809
-
44810
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
44811
- count = zval_get_long(&retval);
44812
- zval_ptr_dtor(&retval);
44813
- /* Else if the object has a count handler defined */
44814
- } else if (zobj->handlers->count_elements) {
44806
+ /* First, check if the handler is defined as it is faster */
44807
+ if (zobj->handlers->count_elements) {
44815
44808
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
44816
44809
zend_type_error("Parameter must be an array or an object that implements Countable");
44817
44810
}
44818
44811
if (UNEXPECTED(EG(exception))) {
44819
44812
count = 0;
44820
44813
}
44814
+ /* Otherwise check if the object implements Countable and call its count() method */
44815
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
44816
+ zval retval;
44817
+
44818
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
44819
+ count = zval_get_long(&retval);
44820
+ zval_ptr_dtor(&retval);
44821
44821
} else {
44822
44822
zend_type_error("Parameter must be an array or an object that implements Countable");
44823
44823
}
0 commit comments