Tim Bezhashvyly wrote: > Please either throw stones at me or give me enough karma to post it.
Sorry, I have neither the ability to give karma, nor a convenient pile of stones. Christoph Becker wrote: > Note that there is already <https://wiki.php.net/rfc/arrayof>, which has > been declined. The previous RFC was declined at least in part because of technical aspects of the implementation. In particular, because the 'typed array' wasn't implemented as a 'container'; instead the contents of the array would need to be checked each time it was passed from one function to another. i.e. for the functions: function fn1(Foo[] $fooArray) { fn2($fooArray); } function fn2(Foo[] $fooArray) { ... } When fn1() calls fn2(), even though the PHP engine could know that $fooArray contains only Foo elements, because of the way it was implemented, the whole array would be iterated through by the engine, comparing each entry to make sure that it is of type Foo. A new RFC would probably need to address at least that issue. It might also need to address a more general need for generics, rather than just the specific case of arrays with a single type. An alternative approach might be to introduce an RFC to make ArrayObject be usable wherever an array is required. Then people could implement a simple container themselves: class FooArray extends ArrayObject { function offsetSet($index, $newval) { if ($newval instanceof Foo) { throw new TypeError("$newval is not a Foo"); } parent::offsetSet($index, $newval); } } cheers Dan -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php