DEV Community

Discussion on: PHP Array: A Gross Mistake

 
xedinunknown profile image
Anton Ukhanev • Edited

Another perhaps more pragmatic way of explaining this.

By depending on array in my signature, it's the same ISP issue as with depending on ArrayAccess&Countable&iterable - why would you do that? Except that a real concrete array won't pass that typehint in PHP, which is even worse, because it necessitates a userland interface for something so extremely simple.

And I'm not saying that there's really never a reason to depend on ArrayAccess&Countable&iterable. But if you are depending on 3 interfaces by depending on array, you should know well what your reason is. And that I'd be curious to know it.

Thread Thread
 
abhinav1217 profile image
Abhinav Kulshreshtha

This point of view makes sense. You are right, while arrays are one of the way to work on data, in practical real world usage, it is safer to limit exposure.

Thread Thread
 
abhinav1217 profile image
Info Comment hidden by post author - thread only visible in this permalink
Abhinav Kulshreshtha

Now this do make sense. PHP arrays does expose the three interfaces. Although like we know, this is by design, a side-effect of emulating an array using ordered maps. Maybe this is why some frameworks prefer to abstract these. Maybe they will rewrite the internals someday, but it would be tough to do that without breaking the internet.

In a talk by Rasmus Lerdorf, he mentioned how he never intended PHP as a language that we know today, that is why all these inconsistencies in internal apis, the language quirks, etc, are all there because he created PHP to be something else. It was after the fact of PHP's popularity, that he decided to rewrite the language internals from the scratch, in a way that it doesn't break internet, yet become a proper backend language.

 
abhinav1217 profile image
Abhinav Kulshreshtha

Now this do make sense. PHP arrays does expose the three interfaces. Although like we know, this is by design, a side-effect of emulating an array using ordered maps. Maybe this is why some frameworks prefer to abstract these. Maybe they will rewrite the internals someday, but it would be tough to do that without breaking the internet.

In a talk by Rasmus Lerdorf, he mentioned how he never intended PHP as a language that we know today, that is why all these inconsistencies in internal apis, the language quirks, etc, are all there because he created PHP to be something else. It was after the fact of PHP's popularity, that he decided to rewrite the language internals from the scratch, in a way that it doesn't break internet, yet become a proper backend language.

Thread Thread
 
xedinunknown profile image
Anton Ukhanev

Maybe this is why some frameworks prefer to abstract these

Exactly. Because it is just more predictable this way.

I'm glad we have come to an agreement.
Thanks for the amusing conversation :)

Some comments have been hidden by the post's author - find out more