Better return types for getBackingType#8687
Conversation
The only backing types for Enums are int and string. The proper return type for ReflectionEnum::getBackingType() is thus null|ReflectionNamedType. See also php/doc-en#1608
|
Note that some changes to the C source might also be required to more formally guarantee this stricter contract. Unfortunately my C and my php source knowledge is not fluent enough to propose those changes. I think we need to define a new return type somewhere: ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ReflectionEnum_getBackingType, 0, 0, ReflectionNamedType, 1)
ZEND_END_ARG_INFO() |
|
It seems to me that restricting the return type might not work well with tagged unions or other extensions to the current enumerations. @iluuu1994, @Crell, thoughts? |
|
Tagged unions can't be backed so that's not a concern. The type would change if we supported more types as backing types but I'm not sure if that's likely to happen. I'm ok with this change, an assert in |
While I think the assert would go between lines 6869 and 6870 I'm not actually sure what it would look like. (C is not a language I use) Would you mind proposing the code change? Edit: as far as I can tell the pipeline failing is a CI problem, not a code problem. |
|
@SamMousa Something like |
The only backing types for Enums are int and string. The proper return type for ReflectionEnum::getBackingType() is thus null|ReflectionNamedType.
See also php/doc-en#1608