New series: what assistive tech really hears on your checkout page. Start with part one →
Shipwright
Home
PHP Aug 15, 2026 1 min read 143 views

Composer Autoloading, Step by Step

Tomás Herrera

Tomás Herrera

@tomasherrera_

Share
Cover illustration for the article Composer Autoloading, Step by Step

A screencast from an empty folder to PSR-4 autoloading with a classmap fallback. PHP has quietly become a pleasant language to write. Typed properties, enums, readonly classes, and now property hooks remove a lot of the boilerplate that gave it a bad reputation.

Sample footage: Spring, an open movie by the Blender Foundation, released under a Creative Commons licence.

Modern PHP, minus the ceremony

We took a class from a six-year-old codebase and rewrote it with current language features. The result is half the length and, more importantly, the invalid states are no longer representable.

  • Use readonly properties for value objects.
  • Replace string constants with backed enums.
  • Commit a PHPStan baseline and shrink it over time.
  • Autoload everything through Composer.

Static analysis turns those types into guarantees. Start at a low level with a baseline file, raise the level one step per sprint, and never let the baseline grow.

Questions, corrections, and war stories are welcome in the comments. Several of our best follow-up posts started as a reader pointing out something we had missed.

We will revisit this in six months with fresh numbers. If the results change, we will update the post and note what changed at the end.

If you try this on your own project, start with one page or one service rather than the whole codebase. A small experiment gives you real numbers to argue with, and it is easy to roll back if the idea does not fit.

Programs must be written for people to read, and only incidentally for machines to execute.

Harold Abelson, Structure and Interpretation of Computer Programs, 1985

Tomás Herrera

Tomás Herrera

Author

PHP and WordPress developer for fifteen years. Tomás maintains a handful of open-source plugins and a strong opinion about hooks.

Related Posts

Comments 5

Fatima Zahra

Clear, practical, no fluff. More of this, please.

Sofia Rossi

It should work without shell access, you just lose the command-line shortcuts.

Alex Moreno

We tried something similar in 2023 and rolled it back. Curious whether the tooling has caught up since.

Yuki Tanaka

Bookmarked. The code sample alone saved me an afternoon.

Oskar Nilsson

We tried something similar in 2023 and rolled it back. Curious whether the tooling has caught up since.

Leave a comment

Your email will not be published. Sign in for a faster experience.

Supports **bold**, *italic*, and `code`.