2 ms·
PHP 8 is one of the rare few popular languages that have Union/Sum types: private int|float $foo; TypeScript and Python are others. There's really nothing
by karmakaze 4y ago
PHP 8 is one of the rare few popular languages that have Union/Sum types:
private int|float $foo;
TypeScript and Python are others. There's really nothing that bad about PHP compared to other scripting languages. My biggest complaint was the inconsistency of naming/parameters of standard functions. I used the Yii Framework for a project and it was much better than expected and the caching and query optimization features were outstanding.
- lifthrasiir 4y agoNit: 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.