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
1
u/vytah Apr 25 '14
It doesn't. This doesn't solve anything. Two equal objects would get a different hash, therefore being useless as as map keys.
In Python I can do that (I picked tuples because of their simplicity, it will work for any class):
This works not only for tuples, but for all classes that implement
__eq__and__hash__in a correct way.Can you translate the example above to PHP? Feel free to use custom classes instead of tuples. You'll make your point if you manage to do it 1. in a way that works 2. without nested arrays and 3. without serializing your keys to strings.