@@ -1165,61 +1165,33 @@ static bool zend_check_intersection_type_from_cache_slot(zend_type_list *interse
1165
1165
return status ;
1166
1166
}
1167
1167
1168
- static bool zend_type_node_matches (zend_type_node * node , zval * zv )
1168
+ static int zend_type_node_matches (const zend_type_node * node , zval * zv )
1169
1169
{
1170
1170
switch (node -> kind ) {
1171
1171
case ZEND_TYPE_SIMPLE : {
1172
- zend_type type = node -> simple_type ;
1173
- uint32_t type_mask = ZEND_TYPE_FULL_MASK (type );
1174
-
1175
- if ((type_mask & MAY_BE_NULL ) && Z_TYPE_P (zv ) == IS_NULL ) {
1176
- return true;
1177
- }
1178
-
1179
- if (ZEND_TYPE_HAS_NAME (type )) {
1180
- zend_class_entry * ce = zend_lookup_class (ZEND_TYPE_NAME (type ));
1181
- if (ce && Z_TYPE_P (zv ) == IS_OBJECT &&
1182
- instanceof_function (Z_OBJCE_P (zv ), ce )) {
1183
- return true;
1184
- }
1185
- return false;
1186
- }
1187
-
1188
- if ((type_mask & MAY_BE_CALLABLE ) &&
1189
- zend_is_callable (zv , 0 , NULL )) {
1190
- return true;
1191
- }
1192
-
1193
- if ((type_mask & MAY_BE_STATIC ) &&
1194
- zend_value_instanceof_static (zv )) {
1195
- return true;
1196
- }
1197
-
1198
- // Scalar check
1199
- return zend_verify_scalar_type_hint (type_mask , zv ,
1200
- ZEND_ARG_USES_STRICT_TYPES (), 0 );
1172
+ return 2 ;
1201
1173
}
1202
1174
1203
1175
case ZEND_TYPE_UNION : {
1204
1176
for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
1205
1177
if (zend_type_node_matches (node -> compound .types [i ], zv )) {
1206
- return true ;
1178
+ return 1 ;
1207
1179
}
1208
1180
}
1209
- return false ;
1181
+ return 0 ;
1210
1182
}
1211
1183
1212
1184
case ZEND_TYPE_INTERSECTION : {
1213
1185
for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
1214
1186
if (!zend_type_node_matches (node -> compound .types [i ], zv )) {
1215
- return false ;
1187
+ return 0 ;
1216
1188
}
1217
1189
}
1218
- return true ;
1190
+ return 1 ;
1219
1191
}
1220
1192
1221
1193
default :
1222
- return false ;
1194
+ return 0 ;
1223
1195
}
1224
1196
}
1225
1197
@@ -1228,46 +1200,23 @@ static zend_always_inline bool zend_check_type_slow(
1228
1200
zend_type * type , zend_type_node * type_tree , zval * arg , zend_reference * ref , void * * cache_slot ,
1229
1201
bool is_return_type , bool is_internal )
1230
1202
{
1231
- if (EXPECTED (type_tree != NULL )) {
1232
- return zend_type_node_matches (type_tree , arg );
1203
+ if (EXPECTED (type_tree != NULL ) && type_tree -> kind != ZEND_TYPE_SIMPLE ) {
1204
+ const int result = zend_type_node_matches (type_tree , arg );
1205
+ if (result < 2 ) {
1206
+ return result ;
1207
+ }
1233
1208
}
1234
1209
1235
- uint32_t type_mask ;
1236
1210
if (ZEND_TYPE_IS_COMPLEX (* type ) && EXPECTED (Z_TYPE_P (arg ) == IS_OBJECT )) {
1237
- zend_class_entry * ce ;
1238
- if (UNEXPECTED (ZEND_TYPE_HAS_LIST (* type ))) {
1239
- zend_type * list_type ;
1240
- if (ZEND_TYPE_IS_INTERSECTION (* type )) {
1241
- return zend_check_intersection_type_from_cache_slot (ZEND_TYPE_LIST (* type ), Z_OBJCE_P (arg ), & cache_slot );
1242
- } else {
1243
- ZEND_TYPE_LIST_FOREACH (ZEND_TYPE_LIST (* type ), list_type ) {
1244
- if (ZEND_TYPE_IS_INTERSECTION (* list_type )) {
1245
- if (zend_check_intersection_type_from_cache_slot (ZEND_TYPE_LIST (* list_type ), Z_OBJCE_P (arg ), & cache_slot )) {
1246
- return true;
1247
- }
1248
- /* The cache_slot is progressed in zend_check_intersection_type_from_cache_slot() */
1249
- } else {
1250
- ZEND_ASSERT (!ZEND_TYPE_HAS_LIST (* list_type ));
1251
- ce = zend_fetch_ce_from_cache_slot (cache_slot , list_type );
1252
- /* Instance of a single type part of a union is sufficient to pass the type check */
1253
- if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1254
- return true;
1255
- }
1256
- PROGRESS_CACHE_SLOT ();
1257
- }
1258
- } ZEND_TYPE_LIST_FOREACH_END ();
1259
- }
1260
- } else {
1261
- ce = zend_fetch_ce_from_cache_slot (cache_slot , type );
1262
- /* If we have a CE we check if it satisfies the type constraint,
1263
- * otherwise it will check if a standard type satisfies it. */
1264
- if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1265
- return true;
1266
- }
1211
+ const zend_class_entry * ce = zend_fetch_ce_from_cache_slot (cache_slot , type );
1212
+ /* If we have a CE we check if it satisfies the type constraint,
1213
+ * otherwise it will check if a standard type satisfies it. */
1214
+ if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1215
+ return true;
1267
1216
}
1268
1217
}
1269
1218
1270
- type_mask = ZEND_TYPE_FULL_MASK (* type );
1219
+ const uint32_t type_mask = ZEND_TYPE_FULL_MASK (* type );
1271
1220
if ((type_mask & MAY_BE_CALLABLE ) &&
1272
1221
zend_is_callable (arg , is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0 , NULL )) {
1273
1222
return 1 ;
0 commit comments