@@ -9270,21 +9270,21 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
9270
9270
count = zend_array_count(Z_ARRVAL_P(op1));
9271
9271
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
9272
9272
zend_object *zobj = Z_OBJ_P(op1);
9273
- /* if the object implements Countable we call its count() method */
9274
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9275
- zval retval;
9276
-
9277
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9278
- count = zval_get_long(&retval);
9279
- zval_ptr_dtor(&retval);
9280
- /* Else if the object has a count handler defined */
9281
- } else if (zobj->handlers->count_elements) {
9273
+ /* First, check if the handler is defined as it is faster */
9274
+ if (zobj->handlers->count_elements) {
9282
9275
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
9283
9276
zend_type_error("Parameter must be an array or an object that implements Countable");
9284
9277
}
9285
9278
if (UNEXPECTED(EG(exception))) {
9286
9279
count = 0;
9287
9280
}
9281
+ /* Otherwise check if the object implements Countable and call its count() method */
9282
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9283
+ zval retval;
9284
+
9285
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9286
+ count = zval_get_long(&retval);
9287
+ zval_ptr_dtor(&retval);
9288
9288
} else {
9289
9289
zend_type_error("Parameter must be an array or an object that implements Countable");
9290
9290
}
@@ -16279,21 +16279,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
16279
16279
count = zend_array_count(Z_ARRVAL_P(op1));
16280
16280
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
16281
16281
zend_object *zobj = Z_OBJ_P(op1);
16282
- /* if the object implements Countable we call its count() method */
16283
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16284
- zval retval;
16285
-
16286
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16287
- count = zval_get_long(&retval);
16288
- zval_ptr_dtor(&retval);
16289
- /* Else if the object has a count handler defined */
16290
- } else if (zobj->handlers->count_elements) {
16282
+ /* First, check if the handler is defined as it is faster */
16283
+ if (zobj->handlers->count_elements) {
16291
16284
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
16292
16285
zend_type_error("Parameter must be an array or an object that implements Countable");
16293
16286
}
16294
16287
if (UNEXPECTED(EG(exception))) {
16295
16288
count = 0;
16296
16289
}
16290
+ /* Otherwise check if the object implements Countable and call its count() method */
16291
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16292
+ zval retval;
16293
+
16294
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16295
+ count = zval_get_long(&retval);
16296
+ zval_ptr_dtor(&retval);
16297
16297
} else {
16298
16298
zend_type_error("Parameter must be an array or an object that implements Countable");
16299
16299
}
@@ -45039,21 +45039,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
45039
45039
count = zend_array_count(Z_ARRVAL_P(op1));
45040
45040
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
45041
45041
zend_object *zobj = Z_OBJ_P(op1);
45042
- /* if the object implements Countable we call its count() method */
45043
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
45044
- zval retval;
45045
-
45046
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
45047
- count = zval_get_long(&retval);
45048
- zval_ptr_dtor(&retval);
45049
- /* Else if the object has a count handler defined */
45050
- } else if (zobj->handlers->count_elements) {
45042
+ /* First, check if the handler is defined as it is faster */
45043
+ if (zobj->handlers->count_elements) {
45051
45044
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
45052
45045
zend_type_error("Parameter must be an array or an object that implements Countable");
45053
45046
}
45054
45047
if (UNEXPECTED(EG(exception))) {
45055
45048
count = 0;
45056
45049
}
45050
+ /* Otherwise check if the object implements Countable and call its count() method */
45051
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
45052
+ zval retval;
45053
+
45054
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
45055
+ count = zval_get_long(&retval);
45056
+ zval_ptr_dtor(&retval);
45057
45057
} else {
45058
45058
zend_type_error("Parameter must be an array or an object that implements Countable");
45059
45059
}
0 commit comments