4 ms·
write PHP a lot. every day. I wish we had typed arrays. Totally not gonna happen, theres been RFCs but I have enough boilerplate classes that are like Class O
by calvinmorrison 1y ago
write PHP a lot. every day.
I wish we had typed arrays. Totally not gonna happen, theres been RFCs but I have enough boilerplate classes that are like
Class Option
Class Options implements Iterator, countable, etc.
Options[0], Options[1], Options[2]
or Options->getOption('some.option.something');
A lot of wrapper stuff like that is semi tedious, the implementation can vary wildly.
Also because a lot of times in php you start with a generic array and decide you need structure around it so you implement a class, then you need an array of class,
Not to mention a bunch of WSDLs that autogenerate ArrayOfString classes...
- wesammikhail 1y agoNailed it. This is the core problem with PHP for me.I love PHP and use it every day. Part of that is the strength and versatility of the arrays implementation (i.e. hashmap). However, the problem is always the fact that an array cant be typed. IF they could just introduce that, it would solve 80% of user-land issues over night.
- bakje 1y agoWe used to have a lot of classes like that, but for us PHPStan is sufficient and we effectively have generics now through static analysis warning us of improper usage of types in our CI and IDEs. Is this not suitable for you?
- makeitdouble 1y agoUse cases might be different than parent, but PHPStan while being the best tool available is far from perfect, there's still a lo of logic it can't follow. First class citizen array type support baked into the language would hopefully behave better.
- bakje 1y agoOh absolutely, but simply for typed arrays it should suffice