3 ms·
Nit: these are called "untagged" union types, as opposed to much more common "tagged" union types (aka algebraic data types or ADTs) where each variant is named
by lifthrasiir 4y ago
Nit: these are called "untagged" union types, as opposed to much more common "tagged" union types (aka algebraic data types or ADTs) where each variant is named and distinct from each other even when types are same. Untagged union types are uncommon mainly because it complicates a type checker for little reason, and most frequently found where types were added as an afterthought and the base language couldn't be changed. In the case of PHP though, it doesn't have structural typing (unlike TypeScript) and every variant should be nominal or primitive types, so this is of the least concern.
- karmakaze 4y agoMany languages that don't have these (untagged) union types, usually also have an open issue discussing if/when they'll be added. I've hand several occasions to want to use them where the available nominal sealed/enum type of the language is insufficient. In these cases it didn't matter if the components of the union were nominal, only that the union type itself wasn't.