@@ -9275,21 +9275,21 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
9275
9275
count = zend_array_count(Z_ARRVAL_P(op1));
9276
9276
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
9277
9277
zend_object *zobj = Z_OBJ_P(op1);
9278
- /* if the object implements Countable we call its count() method */
9279
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9280
- zval retval;
9281
-
9282
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9283
- count = zval_get_long(&retval);
9284
- zval_ptr_dtor(&retval);
9285
- /* Else if the object has a count handler defined */
9286
- } else if (zobj->handlers->count_elements) {
9278
+ /* First, check if the handler is defined as it is faster */
9279
+ if (zobj->handlers->count_elements) {
9287
9280
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
9288
9281
zend_type_error("Parameter must be an array or an object that implements Countable");
9289
9282
}
9290
9283
if (UNEXPECTED(EG(exception))) {
9291
9284
count = 0;
9292
9285
}
9286
+ /* Otherwise check if the object implements Countable and call its count() method */
9287
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
9288
+ zval retval;
9289
+
9290
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9291
+ count = zval_get_long(&retval);
9292
+ zval_ptr_dtor(&retval);
9293
9293
} else {
9294
9294
zend_type_error("Parameter must be an array or an object that implements Countable");
9295
9295
}
@@ -16347,21 +16347,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
16347
16347
count = zend_array_count(Z_ARRVAL_P(op1));
16348
16348
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
16349
16349
zend_object *zobj = Z_OBJ_P(op1);
16350
- /* if the object implements Countable we call its count() method */
16351
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16352
- zval retval;
16353
-
16354
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16355
- count = zval_get_long(&retval);
16356
- zval_ptr_dtor(&retval);
16357
- /* Else if the object has a count handler defined */
16358
- } else if (zobj->handlers->count_elements) {
16350
+ /* First, check if the handler is defined as it is faster */
16351
+ if (zobj->handlers->count_elements) {
16359
16352
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
16360
16353
zend_type_error("Parameter must be an array or an object that implements Countable");
16361
16354
}
16362
16355
if (UNEXPECTED(EG(exception))) {
16363
16356
count = 0;
16364
16357
}
16358
+ /* Otherwise check if the object implements Countable and call its count() method */
16359
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
16360
+ zval retval;
16361
+
16362
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
16363
+ count = zval_get_long(&retval);
16364
+ zval_ptr_dtor(&retval);
16365
16365
} else {
16366
16366
zend_type_error("Parameter must be an array or an object that implements Countable");
16367
16367
}
@@ -45187,21 +45187,21 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
45187
45187
count = zend_array_count(Z_ARRVAL_P(op1));
45188
45188
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
45189
45189
zend_object *zobj = Z_OBJ_P(op1);
45190
- /* if the object implements Countable we call its count() method */
45191
- if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
45192
- zval retval;
45193
-
45194
- zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
45195
- count = zval_get_long(&retval);
45196
- zval_ptr_dtor(&retval);
45197
- /* Else if the object has a count handler defined */
45198
- } else if (zobj->handlers->count_elements) {
45190
+ /* First, check if the handler is defined as it is faster */
45191
+ if (zobj->handlers->count_elements) {
45199
45192
if (FAILURE == zobj->handlers->count_elements(zobj, &count)) {
45200
45193
zend_type_error("Parameter must be an array or an object that implements Countable");
45201
45194
}
45202
45195
if (UNEXPECTED(EG(exception))) {
45203
45196
count = 0;
45204
45197
}
45198
+ /* Otherwise check if the object implements Countable and call its count() method */
45199
+ } else if (zend_class_implements_interface(zobj->ce, zend_ce_countable)) {
45200
+ zval retval;
45201
+
45202
+ zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
45203
+ count = zval_get_long(&retval);
45204
+ zval_ptr_dtor(&retval);
45205
45205
} else {
45206
45206
zend_type_error("Parameter must be an array or an object that implements Countable");
45207
45207
}
0 commit comments