@@ -60,6 +60,7 @@ PHPAPI zend_class_entry *reflection_function_ptr;
6060PHPAPI zend_class_entry * reflection_generator_ptr ;
6161PHPAPI zend_class_entry * reflection_parameter_ptr ;
6262PHPAPI zend_class_entry * reflection_type_ptr ;
63+ PHPAPI zend_class_entry * reflection_named_type_ptr ;
6364PHPAPI zend_class_entry * reflection_class_ptr ;
6465PHPAPI zend_class_entry * reflection_object_ptr ;
6566PHPAPI zend_class_entry * reflection_method_ptr ;
@@ -1276,7 +1277,7 @@ static void reflection_type_factory(zend_function *fptr, zval *closure_object, s
12761277 reflection_object * intern ;
12771278 type_reference * reference ;
12781279
1279- reflection_instantiate (reflection_type_ptr , object );
1280+ reflection_instantiate (reflection_named_type_ptr , object );
12801281 intern = Z_REFLECTION_P (object );
12811282 reference = (type_reference * ) emalloc (sizeof (type_reference ));
12821283 reference -> arg_info = arg_info ;
@@ -2999,35 +3000,66 @@ ZEND_METHOD(reflection_type, isBuiltin)
29993000}
30003001/* }}} */
30013002
3003+ /* {{{ reflection_type_name */
3004+ static zend_string * reflection_type_name (type_reference * param ) {
3005+ switch (param -> arg_info -> type_hint ) {
3006+ case IS_ARRAY : return zend_string_init ("array" , sizeof ("array" ) - 1 , 0 );
3007+ case IS_CALLABLE : return zend_string_init ("callable" , sizeof ("callable" ) - 1 , 0 );
3008+ case IS_OBJECT :
3009+ if (param -> fptr -> type == ZEND_INTERNAL_FUNCTION &&
3010+ !(param -> fptr -> common .fn_flags & ZEND_ACC_USER_ARG_INFO )) {
3011+ return zend_string_init (((zend_internal_arg_info * )param -> arg_info )-> class_name , strlen (((zend_internal_arg_info * )param -> arg_info )-> class_name ), 0 );
3012+ }
3013+ return zend_string_copy (param -> arg_info -> class_name );
3014+ case IS_STRING : return zend_string_init ("string" , sizeof ("string" ) - 1 , 0 );
3015+ case _IS_BOOL : return zend_string_init ("bool" , sizeof ("bool" ) - 1 , 0 );
3016+ case IS_LONG : return zend_string_init ("int" , sizeof ("int" ) - 1 , 0 );
3017+ case IS_DOUBLE : return zend_string_init ("float" , sizeof ("float" ) - 1 , 0 );
3018+ case IS_VOID : return zend_string_init ("void" , sizeof ("void" ) - 1 , 0 );
3019+ case IS_ITERABLE : return zend_string_init ("iterable" , sizeof ("iterable" ) - 1 , 0 );
3020+ EMPTY_SWITCH_DEFAULT_CASE ()
3021+ }
3022+ }
3023+ /* }}} */
3024+
30023025/* {{{ proto public string ReflectionType::__toString()
30033026 Return the text of the type hint */
30043027ZEND_METHOD (reflection_type , __toString )
30053028{
30063029 reflection_object * intern ;
30073030 type_reference * param ;
3031+ zend_string * str ;
30083032
30093033 if (zend_parse_parameters_none () == FAILURE ) {
30103034 return ;
30113035 }
30123036 GET_REFLECTION_OBJECT_PTR (param );
3037+
3038+ str = reflection_type_name (param );
3039+
3040+ if (param -> arg_info -> allow_null ) {
3041+ str = zend_string_extend (str , ZSTR_LEN (str ) + 1 , 0 );
3042+ memmove (ZSTR_VAL (str ) + 1 , ZSTR_VAL (str ), ZSTR_LEN (str ) + 1 );
3043+ ZSTR_VAL (str )[0 ] = '?' ;
3044+ }
3045+
3046+ RETURN_STR (str );
3047+ }
3048+ /* }}} */
30133049
3014- switch (param -> arg_info -> type_hint ) {
3015- case IS_ARRAY : RETURN_STRINGL ("array" , sizeof ("array" ) - 1 );
3016- case IS_CALLABLE : RETURN_STRINGL ("callable" , sizeof ("callable" ) - 1 );
3017- case IS_OBJECT :
3018- if (param -> fptr -> type == ZEND_INTERNAL_FUNCTION &&
3019- !(param -> fptr -> common .fn_flags & ZEND_ACC_USER_ARG_INFO )) {
3020- RETURN_STRING (((zend_internal_arg_info * )param -> arg_info )-> class_name );
3021- }
3022- RETURN_STR_COPY (param -> arg_info -> class_name );
3023- case IS_STRING : RETURN_STRINGL ("string" , sizeof ("string" ) - 1 );
3024- case _IS_BOOL : RETURN_STRINGL ("bool" , sizeof ("bool" ) - 1 );
3025- case IS_LONG : RETURN_STRINGL ("int" , sizeof ("int" ) - 1 );
3026- case IS_DOUBLE : RETURN_STRINGL ("float" , sizeof ("float" ) - 1 );
3027- case IS_VOID : RETURN_STRINGL ("void" , sizeof ("void" ) - 1 );
3028- case IS_ITERABLE : RETURN_STRINGL ("iterable" , sizeof ("iterable" ) - 1 );
3029- EMPTY_SWITCH_DEFAULT_CASE ()
3050+ /* {{{ proto public string ReflectionNamedType::getName()
3051+ Return the text of the type hint */
3052+ ZEND_METHOD (reflection_named_type , getName )
3053+ {
3054+ reflection_object * intern ;
3055+ type_reference * param ;
3056+
3057+ if (zend_parse_parameters_none () == FAILURE ) {
3058+ return ;
30303059 }
3060+ GET_REFLECTION_OBJECT_PTR (param );
3061+
3062+ RETURN_STR (reflection_type_name (param ));
30313063}
30323064/* }}} */
30333065
@@ -6688,6 +6720,11 @@ static const zend_function_entry reflection_type_functions[] = {
66886720 PHP_FE_END
66896721};
66906722
6723+ static const zend_function_entry reflection_named_type_functions [] = {
6724+ ZEND_ME (reflection_named_type , getName , arginfo_reflection__void , 0 )
6725+ PHP_FE_END
6726+ };
6727+
66916728ZEND_BEGIN_ARG_INFO_EX (arginfo_reflection_extension_export , 0 , 0 , 1 )
66926729 ZEND_ARG_INFO (0 , name )
66936730 ZEND_ARG_INFO (0 , return )
@@ -6804,6 +6841,10 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */
68046841 INIT_CLASS_ENTRY (_reflection_entry , "ReflectionType" , reflection_type_functions );
68056842 _reflection_entry .create_object = reflection_objects_new ;
68066843 reflection_type_ptr = zend_register_internal_class (& _reflection_entry );
6844+
6845+ INIT_CLASS_ENTRY (_reflection_entry , "ReflectionNamedType" , reflection_named_type_functions );
6846+ _reflection_entry .create_object = reflection_objects_new ;
6847+ reflection_named_type_ptr = zend_register_internal_class_ex (& _reflection_entry , reflection_type_ptr );
68076848
68086849 INIT_CLASS_ENTRY (_reflection_entry , "ReflectionMethod" , reflection_method_functions );
68096850 _reflection_entry .create_object = reflection_objects_new ;
0 commit comments