On Dec 18, 2012, at 9:43 AM, Victor Berchet <vic...@suumit.com> wrote:
> Dear all: > > I would like to get your feedback on implementing some more data structure in > the PHP core. > > Things like Set, Map could be really helpful. > > A Set would be an unordered collection with no duplicate elements (same as in > Python) > > $setA = new Set(); > $setA->append('a'); > $setA->append('a'); > > $setB = new Set(); > $setB->append('b'); > > $setA == $setB; > > // A set can hold objects > $set->append($object); > > A Map would be an associative array that can hold objects (same as Python > dictionaries) > > $map= new Map(); > > $map[$setA] = 'Hello, world!'; > echo $maps[$setB]; // Hello, world ! Most of what you're looking for can be accomplished by implementing ArrayAccess in your own classes, or using the ArrayObject generically like so: php > $obj = new ArrayObject(array()); php > $obj->append('some string'); php > $obj->append(new ArrayObject(array())); php > var_dump($obj[1]); class ArrayObject#4 (0) { } php > var_dump($obj[0]); string(11) "some string" For the duplicate issue you're referring to, you'd need to implement your own methods for removing (e.g. array_unique). > > I can not really help with the implementation, however I could help defining > the API, creating a test suite and docs should this idea be accepted. > > Note: I had to implement this in PHP while working on Automaton, it's tedious > and inefficient. > > Thanks for your feedback, > Victor > > > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php