| ▲ | deaddodo 2 hours ago | |
It has nothing to do with being “too hard”, and everything to do with not making sense to the type system. PHP is weakly-typed and heavily reflection-based (so everything is aware of it’s and each other’s type at all times). Adding generics to PHP would make CS fundamentalists somewhat happy, but do nothing to change the fundamental design of PHP nor offer any of the traditional benefits that generics offer to strongly-typed and compiled languages. And would be a massive headache to implement, while bulking an already heavy VM implementation. | ||
| ▲ | phplovesong 40 minutes ago | parent [-] | |
> And would be a massive headache to implement Exactly. The type system was never built for anything even slightly more complex. Its basically annotations for primitive types and classes. PHP has always had an weak type system, so adding generics will most likely never happen. > Adding generics to PHP would make CS fundamentalists somewhat happy PHP has really only one collection datatype (the infamous array), so having generics would be tremendously useful, as an example you cant return an typed array from a function, witch is just really bad. For an counter example, Python managed to do this, while also being a dynamic language, although having a stronger typing than PHP. | ||