@@ -1202,61 +1202,33 @@ static bool zend_check_intersection_type_from_cache_slot(zend_type_list *interse
1202
1202
return status ;
1203
1203
}
1204
1204
1205
- static bool zend_type_node_matches (zend_type_node * node , zval * zv )
1205
+ static int zend_type_node_matches (const zend_type_node * node , zval * zv )
1206
1206
{
1207
1207
switch (node -> kind ) {
1208
1208
case ZEND_TYPE_SIMPLE : {
1209
- zend_type type = node -> simple_type ;
1210
- uint32_t type_mask = ZEND_TYPE_FULL_MASK (type );
1211
-
1212
- if ((type_mask & MAY_BE_NULL ) && Z_TYPE_P (zv ) == IS_NULL ) {
1213
- return true;
1214
- }
1215
-
1216
- if (ZEND_TYPE_HAS_NAME (type )) {
1217
- zend_class_entry * ce = zend_lookup_class (ZEND_TYPE_NAME (type ));
1218
- if (ce && Z_TYPE_P (zv ) == IS_OBJECT &&
1219
- instanceof_function (Z_OBJCE_P (zv ), ce )) {
1220
- return true;
1221
- }
1222
- return false;
1223
- }
1224
-
1225
- if ((type_mask & MAY_BE_CALLABLE ) &&
1226
- zend_is_callable (zv , 0 , NULL )) {
1227
- return true;
1228
- }
1229
-
1230
- if ((type_mask & MAY_BE_STATIC ) &&
1231
- zend_value_instanceof_static (zv )) {
1232
- return true;
1233
- }
1234
-
1235
- // Scalar check
1236
- return zend_verify_scalar_type_hint (type_mask , zv ,
1237
- ZEND_ARG_USES_STRICT_TYPES (), 0 );
1209
+ return 2 ;
1238
1210
}
1239
1211
1240
1212
case ZEND_TYPE_UNION : {
1241
1213
for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
1242
1214
if (zend_type_node_matches (node -> compound .types [i ], zv )) {
1243
- return true ;
1215
+ return 1 ;
1244
1216
}
1245
1217
}
1246
- return false ;
1218
+ return 0 ;
1247
1219
}
1248
1220
1249
1221
case ZEND_TYPE_INTERSECTION : {
1250
1222
for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
1251
1223
if (!zend_type_node_matches (node -> compound .types [i ], zv )) {
1252
- return false ;
1224
+ return 0 ;
1253
1225
}
1254
1226
}
1255
- return true ;
1227
+ return 1 ;
1256
1228
}
1257
1229
1258
1230
default :
1259
- return false ;
1231
+ return 0 ;
1260
1232
}
1261
1233
}
1262
1234
@@ -1265,46 +1237,23 @@ static zend_always_inline bool zend_check_type_slow(
1265
1237
zend_type * type , zend_type_node * type_tree , zval * arg , zend_reference * ref , void * * cache_slot ,
1266
1238
bool is_return_type , bool is_internal )
1267
1239
{
1268
- if (EXPECTED (type_tree != NULL )) {
1269
- return zend_type_node_matches (type_tree , arg );
1240
+ if (EXPECTED (type_tree != NULL ) && type_tree -> kind != ZEND_TYPE_SIMPLE ) {
1241
+ const int result = zend_type_node_matches (type_tree , arg );
1242
+ if (result < 2 ) {
1243
+ return result ;
1244
+ }
1270
1245
}
1271
1246
1272
- uint32_t type_mask ;
1273
1247
if (ZEND_TYPE_IS_COMPLEX (* type ) && EXPECTED (Z_TYPE_P (arg ) == IS_OBJECT )) {
1274
- zend_class_entry * ce ;
1275
- if (UNEXPECTED (ZEND_TYPE_HAS_LIST (* type ))) {
1276
- zend_type * list_type ;
1277
- if (ZEND_TYPE_IS_INTERSECTION (* type )) {
1278
- return zend_check_intersection_type_from_cache_slot (ZEND_TYPE_LIST (* type ), Z_OBJCE_P (arg ), & cache_slot );
1279
- } else {
1280
- ZEND_TYPE_LIST_FOREACH (ZEND_TYPE_LIST (* type ), list_type ) {
1281
- if (ZEND_TYPE_IS_INTERSECTION (* list_type )) {
1282
- if (zend_check_intersection_type_from_cache_slot (ZEND_TYPE_LIST (* list_type ), Z_OBJCE_P (arg ), & cache_slot )) {
1283
- return true;
1284
- }
1285
- /* The cache_slot is progressed in zend_check_intersection_type_from_cache_slot() */
1286
- } else {
1287
- ZEND_ASSERT (!ZEND_TYPE_HAS_LIST (* list_type ));
1288
- ce = zend_fetch_ce_from_cache_slot (cache_slot , list_type );
1289
- /* Instance of a single type part of a union is sufficient to pass the type check */
1290
- if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1291
- return true;
1292
- }
1293
- PROGRESS_CACHE_SLOT ();
1294
- }
1295
- } ZEND_TYPE_LIST_FOREACH_END ();
1296
- }
1297
- } else {
1298
- ce = zend_fetch_ce_from_cache_slot (cache_slot , type );
1299
- /* If we have a CE we check if it satisfies the type constraint,
1300
- * otherwise it will check if a standard type satisfies it. */
1301
- if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1302
- return true;
1303
- }
1248
+ const zend_class_entry * ce = zend_fetch_ce_from_cache_slot (cache_slot , type );
1249
+ /* If we have a CE we check if it satisfies the type constraint,
1250
+ * otherwise it will check if a standard type satisfies it. */
1251
+ if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1252
+ return true;
1304
1253
}
1305
1254
}
1306
1255
1307
- type_mask = ZEND_TYPE_FULL_MASK (* type );
1256
+ const uint32_t type_mask = ZEND_TYPE_FULL_MASK (* type );
1308
1257
if ((type_mask & MAY_BE_CALLABLE ) &&
1309
1258
zend_is_callable (arg , is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0 , NULL )) {
1310
1259
return 1 ;
0 commit comments