logoalt Hacker News

calvinmorrisonlast Monday at 1:05 AM2 repliesview on HN

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...


Replies

wesammikhaillast Monday at 1:47 AM

Nailed 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.

bakjelast Monday at 9:12 AM

We 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?

show 1 reply