Replacing a page of getters and setters with hooks, and where we drew the line. 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.

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.
Refactoring the old version
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.
Adding manpower to a late software project makes it later.
Fred Brooks, The Mythical Man-Month, 1975
Quick takeaway
Make invalid states impossible and let the analyser prove it.
Static analysis catches the rest
Typed everything
Properties, parameters, and returns all declare types.
Readonly
Value objects cannot change after construction.
Analysed
PHPStan runs on every pull request.
None of this requires a framework. The examples run on plain PHP 8.3 or newer with Composer’s autoloader, and they translate directly to Laravel or Symfony projects.
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.
We have been running this approach for several months now. The initial setup took about a day, and the ongoing cost is close to zero once the team knows where to look.
None of this is new, and that is the point. The techniques that last are usually the boring ones that are documented well and supported by the platform itself.
Wrapping up
As always, the examples are simplified to fit on a page. The production version has more error handling and logging, but the shape of the code is the same.
Would this still apply on shared hosting without shell access?
Solid write-up. The warning about caching bit us hard last year.
Solid write-up. The warning about caching bit us hard last year.