@@ -1165,61 +1165,33 @@ static bool zend_check_intersection_type_from_cache_slot(zend_type_list *interse
11651165 return status ;
11661166}
11671167
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 )
11691169{
11701170 switch (node -> kind ) {
11711171 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 ;
12011173 }
12021174
12031175 case ZEND_TYPE_UNION : {
12041176 for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
12051177 if (zend_type_node_matches (node -> compound .types [i ], zv )) {
1206- return true ;
1178+ return 1 ;
12071179 }
12081180 }
1209- return false ;
1181+ return 0 ;
12101182 }
12111183
12121184 case ZEND_TYPE_INTERSECTION : {
12131185 for (uint32_t i = 0 ; i < node -> compound .num_types ; i ++ ) {
12141186 if (!zend_type_node_matches (node -> compound .types [i ], zv )) {
1215- return false ;
1187+ return 0 ;
12161188 }
12171189 }
1218- return true ;
1190+ return 1 ;
12191191 }
12201192
12211193 default :
1222- return false ;
1194+ return 0 ;
12231195 }
12241196}
12251197
@@ -1228,46 +1200,23 @@ static zend_always_inline bool zend_check_type_slow(
12281200 zend_type * type , zend_type_node * type_tree , zval * arg , zend_reference * ref , void * * cache_slot ,
12291201 bool is_return_type , bool is_internal )
12301202{
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+ }
12331208 }
12341209
1235- uint32_t type_mask ;
12361210 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;
12671216 }
12681217 }
12691218
1270- type_mask = ZEND_TYPE_FULL_MASK (* type );
1219+ const uint32_t type_mask = ZEND_TYPE_FULL_MASK (* type );
12711220 if ((type_mask & MAY_BE_CALLABLE ) &&
12721221 zend_is_callable (arg , is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0 , NULL )) {
12731222 return 1 ;
0 commit comments