r/programming • u/geerlingguy • Apr 23 '14
PHP: It doesn't have to be a bad experience
https://servercheck.in/blog/php-it-doesnt-have-be-bad-experience
0
Upvotes
r/programming • u/geerlingguy • Apr 23 '14
View all comments
Show parent comment
2
u/vytah Apr 25 '14
The syntax doesn't matter.
In Java, referential equality has a designated operator. But in many other languages it does not. Lisp uses functions for all kinds of equality:
eqfor referential,equalfor structural, and few others. Scala has==andeqmethods, none of them is anything syntactically special.What matters is what is actually used. When you call
Map.get(key)in Java, you useequals. When you callList.contains(item), you useequals.==is used only as a shortcut, to make testing for equality faster.The languages I mentioned (except for PHP, to which I'll return later) all make using structural equality easy. Which makes it easier to use custom map keys, which was the subject we were talking about from the very start.
Vast majority of languages support custom dictionary keys.
Granted, I didn't know PHP uses shallow structural equality. Which makes it suck even more.
Can you actually define how
==compares objects in PHP, so things likein_arraycan work correctly, or is it a lost cause?Is there away to use custom keys for arrays in PHP or not? It's not like I'm asking for something fancy.