@@ -3121,22 +3121,25 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CONST_H
3121
3121
} else {
3122
3122
ZVAL_EMPTY_ARRAY(result);
3123
3123
}
3124
- } else if (Z_OBJ_HT_P(expr)->get_properties) {
3125
- HashTable *obj_ht = Z_OBJ_HT_P(expr)->get_properties(expr);
3126
- if (obj_ht) {
3127
- /* fast copy */
3128
- obj_ht = zend_proptable_to_symtable(obj_ht,
3129
- (Z_OBJCE_P(expr)->default_properties_count ||
3130
- Z_OBJ_P(expr)->handlers != &std_object_handlers ||
3131
- GC_IS_RECURSIVE(obj_ht)));
3132
- ZVAL_ARR(result, obj_ht);
3133
- } else {
3134
- ZVAL_EMPTY_ARRAY(result);
3135
- }
3136
3124
} else {
3137
- ZVAL_COPY_VALUE(result, expr);
3138
- Z_ADDREF_P(result);
3139
- convert_to_array(result);
3125
+ ZVAL_UNDEF(result);
3126
+ if (Z_OBJ_HT_P(expr)->cast_object) {
3127
+ if (Z_OBJ_HT_P(expr)->cast_object(expr, result, IS_ARRAY) == FAILURE) {
3128
+ zend_error(E_RECOVERABLE_ERROR,
3129
+ "Object of class %s could not be converted to array",
3130
+ ZSTR_VAL(Z_OBJCE_P(expr)->name));
3131
+ }
3132
+ } else if (Z_OBJ_HT_P(expr)->get) {
3133
+ zval *newop = Z_OBJ_HT_P(expr)->get(expr, result);
3134
+ if (Z_TYPE_P(newop) != IS_OBJECT) {
3135
+ /* for safety - avoid loop */
3136
+ ZVAL_COPY_VALUE(result, newop);
3137
+ convert_to_array(result);
3138
+ }
3139
+ }
3140
+ if (UNEXPECTED(Z_TYPE_P(result) != IS_ARRAY)) {
3141
+ array_init(result);
3142
+ }
3140
3143
}
3141
3144
} else {
3142
3145
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
@@ -18092,22 +18095,25 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPC
18092
18095
} else {
18093
18096
ZVAL_EMPTY_ARRAY(result);
18094
18097
}
18095
- } else if (Z_OBJ_HT_P(expr)->get_properties) {
18096
- HashTable *obj_ht = Z_OBJ_HT_P(expr)->get_properties(expr);
18097
- if (obj_ht) {
18098
- /* fast copy */
18099
- obj_ht = zend_proptable_to_symtable(obj_ht,
18100
- (Z_OBJCE_P(expr)->default_properties_count ||
18101
- Z_OBJ_P(expr)->handlers != &std_object_handlers ||
18102
- GC_IS_RECURSIVE(obj_ht)));
18103
- ZVAL_ARR(result, obj_ht);
18104
- } else {
18105
- ZVAL_EMPTY_ARRAY(result);
18106
- }
18107
18098
} else {
18108
- ZVAL_COPY_VALUE(result, expr);
18109
- Z_ADDREF_P(result);
18110
- convert_to_array(result);
18099
+ ZVAL_UNDEF(result);
18100
+ if (Z_OBJ_HT_P(expr)->cast_object) {
18101
+ if (Z_OBJ_HT_P(expr)->cast_object(expr, result, IS_ARRAY) == FAILURE) {
18102
+ zend_error(E_RECOVERABLE_ERROR,
18103
+ "Object of class %s could not be converted to array",
18104
+ ZSTR_VAL(Z_OBJCE_P(expr)->name));
18105
+ }
18106
+ } else if (Z_OBJ_HT_P(expr)->get) {
18107
+ zval *newop = Z_OBJ_HT_P(expr)->get(expr, result);
18108
+ if (Z_TYPE_P(newop) != IS_OBJECT) {
18109
+ /* for safety - avoid loop */
18110
+ ZVAL_COPY_VALUE(result, newop);
18111
+ convert_to_array(result);
18112
+ }
18113
+ }
18114
+ if (UNEXPECTED(Z_TYPE_P(result) != IS_ARRAY)) {
18115
+ array_init(result);
18116
+ }
18111
18117
}
18112
18118
} else {
18113
18119
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
@@ -21100,22 +21106,25 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPC
21100
21106
} else {
21101
21107
ZVAL_EMPTY_ARRAY(result);
21102
21108
}
21103
- } else if (Z_OBJ_HT_P(expr)->get_properties) {
21104
- HashTable *obj_ht = Z_OBJ_HT_P(expr)->get_properties(expr);
21105
- if (obj_ht) {
21106
- /* fast copy */
21107
- obj_ht = zend_proptable_to_symtable(obj_ht,
21108
- (Z_OBJCE_P(expr)->default_properties_count ||
21109
- Z_OBJ_P(expr)->handlers != &std_object_handlers ||
21110
- GC_IS_RECURSIVE(obj_ht)));
21111
- ZVAL_ARR(result, obj_ht);
21112
- } else {
21113
- ZVAL_EMPTY_ARRAY(result);
21114
- }
21115
21109
} else {
21116
- ZVAL_COPY_VALUE(result, expr);
21117
- Z_ADDREF_P(result);
21118
- convert_to_array(result);
21110
+ ZVAL_UNDEF(result);
21111
+ if (Z_OBJ_HT_P(expr)->cast_object) {
21112
+ if (Z_OBJ_HT_P(expr)->cast_object(expr, result, IS_ARRAY) == FAILURE) {
21113
+ zend_error(E_RECOVERABLE_ERROR,
21114
+ "Object of class %s could not be converted to array",
21115
+ ZSTR_VAL(Z_OBJCE_P(expr)->name));
21116
+ }
21117
+ } else if (Z_OBJ_HT_P(expr)->get) {
21118
+ zval *newop = Z_OBJ_HT_P(expr)->get(expr, result);
21119
+ if (Z_TYPE_P(newop) != IS_OBJECT) {
21120
+ /* for safety - avoid loop */
21121
+ ZVAL_COPY_VALUE(result, newop);
21122
+ convert_to_array(result);
21123
+ }
21124
+ }
21125
+ if (UNEXPECTED(Z_TYPE_P(result) != IS_ARRAY)) {
21126
+ array_init(result);
21127
+ }
21119
21128
}
21120
21129
} else {
21121
21130
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
@@ -37467,22 +37476,25 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCO
37467
37476
} else {
37468
37477
ZVAL_EMPTY_ARRAY(result);
37469
37478
}
37470
- } else if (Z_OBJ_HT_P(expr)->get_properties) {
37471
- HashTable *obj_ht = Z_OBJ_HT_P(expr)->get_properties(expr);
37472
- if (obj_ht) {
37473
- /* fast copy */
37474
- obj_ht = zend_proptable_to_symtable(obj_ht,
37475
- (Z_OBJCE_P(expr)->default_properties_count ||
37476
- Z_OBJ_P(expr)->handlers != &std_object_handlers ||
37477
- GC_IS_RECURSIVE(obj_ht)));
37478
- ZVAL_ARR(result, obj_ht);
37479
- } else {
37480
- ZVAL_EMPTY_ARRAY(result);
37481
- }
37482
37479
} else {
37483
- ZVAL_COPY_VALUE(result, expr);
37484
- Z_ADDREF_P(result);
37485
- convert_to_array(result);
37480
+ ZVAL_UNDEF(result);
37481
+ if (Z_OBJ_HT_P(expr)->cast_object) {
37482
+ if (Z_OBJ_HT_P(expr)->cast_object(expr, result, IS_ARRAY) == FAILURE) {
37483
+ zend_error(E_RECOVERABLE_ERROR,
37484
+ "Object of class %s could not be converted to array",
37485
+ ZSTR_VAL(Z_OBJCE_P(expr)->name));
37486
+ }
37487
+ } else if (Z_OBJ_HT_P(expr)->get) {
37488
+ zval *newop = Z_OBJ_HT_P(expr)->get(expr, result);
37489
+ if (Z_TYPE_P(newop) != IS_OBJECT) {
37490
+ /* for safety - avoid loop */
37491
+ ZVAL_COPY_VALUE(result, newop);
37492
+ convert_to_array(result);
37493
+ }
37494
+ }
37495
+ if (UNEXPECTED(Z_TYPE_P(result) != IS_ARRAY)) {
37496
+ array_init(result);
37497
+ }
37486
37498
}
37487
37499
} else {
37488
37500
ZVAL_OBJ(result, zend_objects_new(zend_standard_class_def));
0 commit comments