Dependency-free PHP Collections

A few months ago, Beyond Blocks podcast guest Dan Leech give another talk at the PHP South West user group.

This talk was about building an expression language from scratch, but in one part of the talk, Dan showed how he creates Collection classes.

I use Collection classes a lot, have given talks about them and wrote a Collections module for Drupal 7.

In Dan's talk, instead of using a Collection from Laravel or Doctrine, he created his own.

His extended PHP's IteratorAggregate class so had no external dependencies.

He could then add whatever additional methods and functionality he needed.

Looking at other repositories on GitHub, I was able to find other examples.

I've done this on projects since Dan's talk and like taking the minimalist approach - avoiding adding a dependency to my project and only adding the functionality I need and functionality that's more specific to my domain.