← Back to insights

Adopting PHP 8 features in legacy codebases safely

How we introduced named arguments, match expressions, and better types in an older PHP app without big-bang rewrites.

PHPLegacyRefactoringBest practices

Our legacy codebase was on PHP 7.4. We wanted to benefit from PHP 8’s type system and syntax without rewriting everything. We started by enabling strict types in new files and gradually adding return types and property types where we touched code.

Named arguments and match expressions made new code more readable and reduced mistakes when calling functions with many parameters. We used static analysis (PHPStan) at a low level first, then tightened it as we fixed issues.

Over a few months, most of the hot paths were updated. We did not change everything at once; we let the type checker and tests guide us, and we kept deployments small and reversible.

Work with me