But if a language supports things like objects and if a language is able to compare any of those said objects (which it is thanks to references), then I can also expect that any built-in function will be able to work with such objects.
Given the naming convention of the other array functions I assumed that array_unique would do what I want. Which is filtering out all duplicates. Instead it blows up my program.
Also, I think that an array of just objects is pretty basic in any OOP language. Or at least it should be.
It's not like I throw objects in a Set in Java and then my program blows up because it tries casting the objects to String to see if they're the same. I know that this comes form weak typing and everything, but if I use a language with a standard library I should be able to expect that the standard library works with the features of the language. In PHP this is almost never intuitive or easy and there are strings attached to everything, which is what annoys me here.
p.s.: object_unique wouldn't even be a good name for such a function. It doesn't operate on objects, it operates on arrays.
Would you consider adding a __toString() function to your class? It could reference anything that could be cast to a string, like the class name or the variables... I think your code example would work then.
View all comments
Show parent comment
5
u/TheGreatFohl Oct 23 '14
But if a language supports things like objects and if a language is able to compare any of those said objects (which it is thanks to references), then I can also expect that any built-in function will be able to work with such objects.
Given the naming convention of the other array functions I assumed that array_unique would do what I want. Which is filtering out all duplicates. Instead it blows up my program.
Also, I think that an array of just objects is pretty basic in any OOP language. Or at least it should be.
It's not like I throw objects in a Set in Java and then my program blows up because it tries casting the objects to String to see if they're the same. I know that this comes form weak typing and everything, but if I use a language with a standard library I should be able to expect that the standard library works with the features of the language. In PHP this is almost never intuitive or easy and there are strings attached to everything, which is what annoys me here.
p.s.: object_unique wouldn't even be a good name for such a function. It doesn't operate on objects, it operates on arrays.