DEV Community

Discussion on: PHP collection libraries in 2026: doctrine, illuminate, loophp, noctud, ramsey

Collapse
 
delacry profile image
delacry

Hello! Sorry for the late response, and thanks for the feedback!

I haven't tried php/ds yet, because it's shipped as PHP extension, and if you are writing some PHP libraries, you cannot depend on it (you can, but then almost no one can install your lib if they dont have bundled that ext). From what I've seen, the performance of php/ds should be unmatched by any packagist library, because it's native C ext.

Now I've also looked at PSL collection, and it's an array wrapper with nicer API, it naturally performs better than noctud, but doesn't guarantee real type safety, keys could be only string or integer, and if you use string "123" as a key it instantly turns into integer. Also mutability is little bit confusing when propageted, in MutableMap you have keys() which always return new instance like MutableVector::fromArray(array_keys($this->elements));, so technically you can do $map->keys()->add(1) which will have no effect on the map itself but it will work, in noctud $map->keys has no add/remove methods because it's read-only live view.

The ⚠️ cells specifically: noctud's runtime type checks only apply to keys of stringMapOf/intMapOf so map isn't corrupted. If it was allowed to put string as key into integer map it would turn into 0, and there's a rule that whatever key you put into map must stay exactly the same, so StringMap must refuse keys like int(123), because internally it has array<string|int, mixed> store which would allow you to save it, but when reding string map we do int->string conversion.