@@ -9214,21 +9214,21 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
9214
9214
count = zend_array_count(Z_ARRVAL_P(op1));
9215
9215
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
9216
9216
zend_object *zobj = Z_OBJ_P(op1);
9217
- /* if the object implements Countable we call its count() method */
9218
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9219
- zval retval;
9220
-
9221
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9222
- count = zval_get_long(&retval);
9223
- zval_ptr_dtor(&retval);
9224
- /* Else if the object has a count handler defined */
9225
- } else if (zobj->handlers->count_elements) {
9217
+ /* First, check if the handler is defined as it is faster */
9218
+ if (zobj->handlers->count_elements) {
9226
9219
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
9227
9220
zend_type_error("Parameter must be an array or an object that implements Countable");
9228
9221
}
9229
9222
if (UNEXPECTED(EG(exception))) {
9230
9223
count = 0;
9231
9224
}
9225
+ /* Otherwise check if the object implements Countable and call its count() method */
9226
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9227
+ zval retval;
9228
+
9229
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9230
+ count = zval_get_long(&retval);
9231
+ zval_ptr_dtor(&retval);
9232
9232
} else {
9233
9233
zend_type_error("Parameter must be an array or an object that implements Countable");
9234
9234
}
@@ -16229,21 +16229,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
16229
16229
count = zend_array_count(Z_ARRVAL_P(op1));
16230
16230
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
16231
16231
zend_object *zobj = Z_OBJ_P(op1);
16232
- /* if the object implements Countable we call its count() method */
16233
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16234
- zval retval;
16235
-
16236
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16237
- count = zval_get_long(&retval);
16238
- zval_ptr_dtor(&retval);
16239
- /* Else if the object has a count handler defined */
16240
- } else if (zobj->handlers->count_elements) {
16232
+ /* First, check if the handler is defined as it is faster */
16233
+ if (zobj->handlers->count_elements) {
16241
16234
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
16242
16235
zend_type_error("Parameter must be an array or an object that implements Countable");
16243
16236
}
16244
16237
if (UNEXPECTED(EG(exception))) {
16245
16238
count = 0;
16246
16239
}
16240
+ /* Otherwise check if the object implements Countable and call its count() method */
16241
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16242
+ zval retval;
16243
+
16244
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16245
+ count = zval_get_long(&retval);
16246
+ zval_ptr_dtor(&retval);
16247
16247
} else {
16248
16248
zend_type_error("Parameter must be an array or an object that implements Countable");
16249
16249
}
@@ -44742,21 +44742,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
44742
44742
count = zend_array_count(Z_ARRVAL_P(op1));
44743
44743
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
44744
44744
zend_object *zobj = Z_OBJ_P(op1);
44745
- /* if the object implements Countable we call its count() method */
44746
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
44747
- zval retval;
44748
-
44749
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
44750
- count = zval_get_long(&retval);
44751
- zval_ptr_dtor(&retval);
44752
- /* Else if the object has a count handler defined */
44753
- } else if (zobj->handlers->count_elements) {
44745
+ /* First, check if the handler is defined as it is faster */
44746
+ if (zobj->handlers->count_elements) {
44754
44747
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
44755
44748
zend_type_error("Parameter must be an array or an object that implements Countable");
44756
44749
}
44757
44750
if (UNEXPECTED(EG(exception))) {
44758
44751
count = 0;
44759
44752
}
44753
+ /* Otherwise check if the object implements Countable and call its count() method */
44754
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
44755
+ zval retval;
44756
+
44757
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
44758
+ count = zval_get_long(&retval);
44759
+ zval_ptr_dtor(&retval);
44760
44760
} else {
44761
44761
zend_type_error("Parameter must be an array or an object that implements Countable");
44762
44762
}
0 commit comments