icecave / collections

A PHP collection library loosely inspired by the .NET runtime and the C++ STL. [DEPRECATED]
MIT License
70 stars 2 forks source link

PHP issue prevents returning anything other than int/string from Iterator::key(). #34

Closed jmalloc closed 11 years ago

jmalloc commented 11 years ago

PHP Issue: https://bugs.php.net/bug.php?id=45684

This affects both Set and Map. Set was changed in #32 to yield integer strings, unfortunately this is no good for Map.

Workaround:

Iterator::key() is not called if the key value is not used in foreach, so the following workaround will work, however unfortunate:

foreach ($map as $value) {
    $key = $map->key();
    // do work
}
jmalloc commented 11 years ago

The fix for this issue has been accepted into PHP 5.5.