@@ -1202,61 +1202,33 @@ static bool zend_check_intersection_type_from_cache_slot(zend_type_list *interse
12021202 return status ;
12031203}
12041204
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 )
12061206{
12071207 switch (node -> kind ) {
12081208 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 ;
12381210 }
12391211
12401212 case ZEND_TYPE_UNION : {
12411213 for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
12421214 if (zend_type_node_matches (node -> compound .types [i ], zv )) {
1243- return true ;
1215+ return 1 ;
12441216 }
12451217 }
1246- return false ;
1218+ return 0 ;
12471219 }
12481220
12491221 case ZEND_TYPE_INTERSECTION : {
12501222 for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
12511223 if (!zend_type_node_matches (node -> compound .types [i ], zv )) {
1252- return false ;
1224+ return 0 ;
12531225 }
12541226 }
1255- return true ;
1227+ return 1 ;
12561228 }
12571229
12581230 default :
1259- return false ;
1231+ return 0 ;
12601232 }
12611233}
12621234
@@ -1265,46 +1237,23 @@ static zend_always_inline bool zend_check_type_slow(
12651237 zend_type * type , zend_type_node * type_tree , zval * arg , zend_reference * ref , void * * cache_slot ,
12661238 bool is_return_type , bool is_internal )
12671239{
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+ }
12701245 }
12711246
1272- uint32_t type_mask ;
12731247 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;
13041253 }
13051254 }
13061255
1307- type_mask = ZEND_TYPE_FULL_MASK (* type );
1256+ const uint32_t type_mask = ZEND_TYPE_FULL_MASK (* type );
13081257 if ((type_mask & MAY_BE_CALLABLE ) &&
13091258 zend_is_callable (arg , is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0 , NULL )) {
13101259 return 1 ;
0 commit comments