@@ -836,18 +836,15 @@ static zend_class_entry *resolve_single_class_type(zend_string *name, zend_class
836
836
}
837
837
}
838
838
839
- // TODO better name
840
- static zend_always_inline zend_class_entry * zend_resolve_ce (
839
+ static zend_always_inline zend_class_entry * zend_ce_from_type (
841
840
zend_property_info * info , zend_type * type ) {
842
- zend_class_entry * ce ;
843
- zend_string * name = NULL ;
844
-
845
841
if (UNEXPECTED (!ZEND_TYPE_HAS_NAME (* type ))) {
842
+ ZEND_ASSERT (ZEND_TYPE_HAS_CE (* type ));
846
843
return ZEND_TYPE_CE (* type );
847
844
}
848
845
849
- name = ZEND_TYPE_NAME (* type );
850
-
846
+ zend_string * name = ZEND_TYPE_NAME (* type );
847
+ zend_class_entry * ce ;
851
848
if (ZSTR_HAS_CE_CACHE (name )) {
852
849
ce = ZSTR_GET_CE_CACHE (name );
853
850
if (!ce ) {
@@ -865,50 +862,28 @@ static zend_always_inline zend_class_entry* zend_resolve_ce(
865
862
866
863
static bool zend_check_and_resolve_property_class_type (
867
864
zend_property_info * info , zend_class_entry * object_ce ) {
868
- zend_class_entry * ce ;
869
865
if (ZEND_TYPE_HAS_LIST (info -> type )) {
870
866
zend_type * list_type ;
871
-
872
867
if (ZEND_TYPE_IS_INTERSECTION (info -> type )) {
873
868
ZEND_TYPE_LIST_FOREACH (ZEND_TYPE_LIST (info -> type ), list_type ) {
874
- ce = zend_resolve_ce (info , list_type );
875
-
876
- /* If we cannot resolve the CE we cannot check if it satisfies
877
- * the type constraint, fail. */
878
- if (ce == NULL ) {
879
- return false;
880
- }
881
-
882
- if (!instanceof_function (object_ce , ce )) {
869
+ zend_class_entry * ce = zend_ce_from_type (info , list_type );
870
+ if (!ce || !instanceof_function (object_ce , ce )) {
883
871
return false;
884
872
}
885
873
} ZEND_TYPE_LIST_FOREACH_END ();
886
874
return true;
887
875
} else {
888
876
ZEND_TYPE_LIST_FOREACH (ZEND_TYPE_LIST (info -> type ), list_type ) {
889
- ce = zend_resolve_ce (info , list_type );
890
-
891
- /* If we cannot resolve the CE we cannot check if it satisfies
892
- * the type constraint, check the next one. */
893
- if (ce == NULL ) {
894
- continue ;
895
- }
896
- if (instanceof_function (object_ce , ce )) {
877
+ zend_class_entry * ce = zend_ce_from_type (info , list_type );
878
+ if (ce && instanceof_function (object_ce , ce )) {
897
879
return true;
898
880
}
899
881
} ZEND_TYPE_LIST_FOREACH_END ();
900
882
return false;
901
883
}
902
884
} else {
903
- ce = zend_resolve_ce (info , & info -> type );
904
-
905
- /* If we cannot resolve the CE we cannot check if it satisfies
906
- * the type constraint, fail. */
907
- if (ce == NULL ) {
908
- return false;
909
- }
910
-
911
- return instanceof_function (object_ce , ce );
885
+ zend_class_entry * ce = zend_ce_from_type (info , & info -> type );
886
+ return ce && instanceof_function (object_ce , ce );
912
887
}
913
888
}
914
889
@@ -981,39 +956,38 @@ static zend_always_inline bool zend_value_instanceof_static(zval *zv) {
981
956
# define HAVE_CACHE_SLOT 1
982
957
#endif
983
958
984
- static zend_always_inline zend_class_entry * zend_fetch_ce_from_cache_slot (void * * cache_slot , zend_type * type )
959
+ static zend_always_inline zend_class_entry * zend_fetch_ce_from_cache_slot (
960
+ void * * cache_slot , zend_type * type )
985
961
{
986
- zend_class_entry * ce ;
987
-
988
962
if (EXPECTED (HAVE_CACHE_SLOT && * cache_slot )) {
989
- ce = (zend_class_entry * ) * cache_slot ;
990
- } else {
991
- zend_string * name = ZEND_TYPE_NAME (* type );
992
-
993
- if (ZSTR_HAS_CE_CACHE (name )) {
994
- ce = ZSTR_GET_CE_CACHE (name );
995
- if (!ce ) {
996
- ce = zend_lookup_class_ex (name , NULL , ZEND_FETCH_CLASS_NO_AUTOLOAD );
997
- if (UNEXPECTED (!ce )) {
998
- /* Cannot resolve */
999
- return NULL ;
1000
- }
1001
- }
1002
- } else {
1003
- ce = zend_fetch_class (name ,
1004
- ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT );
963
+ return (zend_class_entry * ) * cache_slot ;
964
+ }
965
+
966
+ zend_string * name = ZEND_TYPE_NAME (* type );
967
+ zend_class_entry * ce ;
968
+ if (ZSTR_HAS_CE_CACHE (name )) {
969
+ ce = ZSTR_GET_CE_CACHE (name );
970
+ if (!ce ) {
971
+ ce = zend_lookup_class_ex (name , NULL , ZEND_FETCH_CLASS_NO_AUTOLOAD );
1005
972
if (UNEXPECTED (!ce )) {
973
+ /* Cannot resolve */
1006
974
return NULL ;
1007
975
}
1008
976
}
1009
- if (HAVE_CACHE_SLOT ) {
1010
- * cache_slot = (void * ) ce ;
977
+ } else {
978
+ ce = zend_fetch_class (name ,
979
+ ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT );
980
+ if (UNEXPECTED (!ce )) {
981
+ return NULL ;
1011
982
}
1012
983
}
984
+ if (HAVE_CACHE_SLOT ) {
985
+ * cache_slot = (void * ) ce ;
986
+ }
1013
987
return ce ;
1014
988
}
1015
989
1016
- ZEND_API bool zend_check_type_slow (
990
+ static zend_always_inline bool zend_check_type_slow (
1017
991
zend_type * type , zval * arg , zend_reference * ref , void * * cache_slot ,
1018
992
bool is_return_type , bool is_internal )
1019
993
{
@@ -1025,16 +999,9 @@ ZEND_API bool zend_check_type_slow(
1025
999
if (ZEND_TYPE_IS_INTERSECTION (* type )) {
1026
1000
ZEND_TYPE_LIST_FOREACH (ZEND_TYPE_LIST (* type ), list_type ) {
1027
1001
ce = zend_fetch_ce_from_cache_slot (cache_slot , list_type );
1028
- /* If we cannot resolve the CE we cannot check if it satisfies
1029
- * the type constraint, fail. */
1030
- if (ce == NULL ) {
1031
- return false;
1032
- }
1033
-
1034
- /* Perform actual type check */
1035
1002
/* If type is not an instance of one of the types taking part in the
1036
1003
* intersection it cannot be a valid instance of the whole intersection type. */
1037
- if (!instanceof_function (Z_OBJCE_P (arg ), ce )) {
1004
+ if (!ce || ! instanceof_function (Z_OBJCE_P (arg ), ce )) {
1038
1005
return false;
1039
1006
}
1040
1007
if (HAVE_CACHE_SLOT ) {
@@ -1045,7 +1012,6 @@ ZEND_API bool zend_check_type_slow(
1045
1012
} else {
1046
1013
ZEND_TYPE_LIST_FOREACH (ZEND_TYPE_LIST (* type ), list_type ) {
1047
1014
ce = zend_fetch_ce_from_cache_slot (cache_slot , list_type );
1048
- /* Perform actual type check if we have a CE */
1049
1015
/* Instance of a single type part of a union is sufficient to pass the type check */
1050
1016
if (ce && instanceof_function (Z_OBJCE_P (arg ), ce )) {
1051
1017
return true;
@@ -1113,6 +1079,13 @@ static zend_always_inline bool zend_check_type(
1113
1079
return zend_check_type_slow (type , arg , ref , cache_slot , is_return_type , is_internal );
1114
1080
}
1115
1081
1082
+ ZEND_API bool zend_check_user_type_slow (
1083
+ zend_type * type , zval * arg , zend_reference * ref , void * * cache_slot , bool is_return_type )
1084
+ {
1085
+ return zend_check_type_slow (
1086
+ type , arg , ref , cache_slot , is_return_type , /* is_internal */ false);
1087
+ }
1088
+
1116
1089
static zend_always_inline bool zend_verify_recv_arg_type (zend_function * zf , uint32_t arg_num , zval * arg , void * * cache_slot )
1117
1090
{
1118
1091
zend_arg_info * cur_arg_info ;
0 commit comments