Java's HashSet equivalent in PHP

hashset, java, php, set

Solution

Starting from release 5.2 Php offers SplObjectStorage, that offers functionalities of Java's Set:

- Cares about uniqueness (same object can't be added twice)

- Easy to iterate through the collection

- Easy to check existence of an object in the collection

Check http://technosophos.com/content/set-objects-php-arrays-vs-splobjectstorage for example of use

Problem

I'm relatively new to php and having a hard time figuring out the right data structure to use. Let's say I have a class FooBar with `equals()` and `hashCode()` properly implemented. What kind of collection in php (if there is any at all) that most resembles Java's hashSet? I need a collection of objects without duplicates. Someone's suggested using array and the function `array_key_exists`, but I was just wondering if there's another way to do this?

Original source