Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I often return some collection of types in an array eg [User, Config]. Right now my return type is just "array". To get this to work i need to build yet another wrapper class and all that, and thats just wasteful and totally unnecessary.

A even more simpler example is An array of some sort of Item. I cant return array(Item), but i only can return an array.





What do you mean, "to get this to work"? It's a PHP array. It will return whatever you need it to.

What is not working?


The parts thats not working is if i return a plain "array" i can then put whatever inside it. Its basically the same as "any" but wrapped inside an array.

Sure.

But that is no different than if you created the array in that scope.

So, again: Why is it "really bad" that you can't return a typed array from a function? What is worse about that than not being able to create a typed array in the current scope?

Also: What, exactly, about that is "not working"? As I said above, I understand the basic arguments about typed arrays; they're conceptually equivalent to weak/dynamic types. And there is value in having strong and static types. But it's hardly a showstopper not to, and PHP works just fine even if you don't use any. It just...makes it easier for us, as programmers, to make mistakes.

So to say it's "not working" simply because it's possible to add elements to the array that don't match the types you want seems like an exaggeration.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: