From f732511d09d32705d7d6956edd40e8b9a83b914f Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 30 Mar 2025 14:46:53 +0100 Subject: [PATCH] Add daily email for 2025-03-29 Dependency-free PHP Collections --- source/_daily_emails/2025-03-29.md | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 source/_daily_emails/2025-03-29.md diff --git a/source/_daily_emails/2025-03-29.md b/source/_daily_emails/2025-03-29.md new file mode 100644 index 000000000..a82a6954d --- /dev/null +++ b/source/_daily_emails/2025-03-29.md @@ -0,0 +1,34 @@ +--- +title: Dependency-free PHP Collections +date: 2025-03-29 +permalink: daily/2025/03/29/collections +tags: + - software-development + - php + - collections +cta: ~ +snippet: | + How to write Collection classes in PHP with no dependencies. +--- + +A few months ago, [Beyond Blocks podcast guest Dan Leech][5] give another talk at the PHP South West user group. + +This talk was about [building an expression language from scratch][4], 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][1] and [wrote a Collections module for Drupal 7][2]. + +In Dan's talk, instead of using a Collection from Laravel or Doctrine, [he created his own][3]. + +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. + +[1]: {{site.url}}/presentations/using-illuminate-collections-outside-laravel +[2]: https://www.drupal.org/project/collection_class +[3]: https://github.com/dantleech/onehourexpr/blob/8c4ee4a3c1680455118e16a3e1be2a08418ab207/src/Tokens.php +[4]: https://www.youtube.com/watch?v=UpyVAcWGQhg +[5]: {{site.url}}/podcast/6-dan-leech-php-tui