Jump to the navigation menu

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.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an certified Drupal Triple Expert with 18 years of experience, a Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.