Free course · 35 lessons · Intermediate

PHP 7: Maintaining and Upgrading Legacy Apps

Work confidently in PHP 7 codebases: language features, testing and refactoring legacy code, security hardening, and a safe path to PHP 8.

Start the course

1. PHP 7 Language Essentials

What PHP 7.0–7.4 introduced and what you'll see in real PHP 7 codebases.

  1. What PHP 7 Changed — The PHP 7 engine, scalar and return types, and the Throwable hierarchy.
  2. Null Coalescing, Spaceship and Other Operators — Use ??, <=>, ??= and other PHP 7 conveniences.
  3. PHP 7.1–7.3: Nullable, void, iterable and More — Nullable types, void, iterable, class constant visibility, multi-catch and list() improvements.
  4. PHP 7.4: Typed Properties, Arrow Functions and Preloading — The last PHP 7 release and the features that bridge to PHP 8.
  5. Anonymous Classes, Generators and Closures in PHP 7 — Recognize and modernize idioms common in PHP 7 code.

2. Working in a Legacy PHP Codebase

Find your way around old code, add Composer, tame globals and configuration, and debug production issues.

  1. Reading and Mapping Legacy Code — Build a mental map of an unfamiliar PHP 7 application before changing it.
  2. Introducing Composer to a Legacy Project — Add Composer and autoloading without breaking existing includes.
  3. Taming Globals, Includes and Superglobals — Contain global state so code becomes testable and predictable.
  4. Configuration and Environments — Move hard-coded settings and secrets into environment-based configuration.
  5. Debugging and Logging Legacy Apps — Use Xdebug, error logs and structured logging to understand production behavior.

3. Getting Legacy Code Under Test

Characterization tests, seams and PHPUnit 9 to make change safe.

  1. Characterization Tests — Capture what the code does today before you change it.
  2. Seams and Breaking Dependencies — Create seams so hard-to-test code can be isolated.
  3. PHPUnit for PHP 7 Projects — Choose the right PHPUnit version and configure a test suite for an old codebase.
  4. Golden Master and Approval Tests — Snapshot large outputs like reports and HTML pages to refactor safely.

4. Refactoring Legacy PHP Safely

Small, safe steps: extract functions and classes, replace arrays with objects, and strangle old modules.

  1. Extract Function and Extract Class — Break up long scripts and god classes in small, verifiable steps.
  2. Replacing Associative Arrays with Objects — Turn 'array shapes' into typed DTOs and value objects.
  3. The Strangler Fig Pattern — Replace a legacy app piece by piece behind a routing layer.
  4. Static Analysis on Legacy Code — Adopt PHPStan with a baseline and raise strictness over time.

5. Security Hardening for PHP 7 Apps

Fix the classic vulnerabilities in old PHP code: SQL injection, weak password hashes, XSS, sessions and outdated dependencies.

  1. Migrating from mysql_* and String SQL to PDO — Remove injection-prone queries and dead extensions.
  2. Upgrading Weak Password Hashes — Move from md5/sha1 hashes to password_hash without forcing resets.
  3. Fixing XSS in Legacy Templates — Systematically escape output in PHP templates mixed with logic.
  4. Hardening Sessions and Authentication — Fix session fixation, insecure cookies and weak 'remember me' implementations.
  5. End-of-Life PHP and Vulnerable Dependencies — Assess and reduce risk when you can't upgrade immediately.

6. Upgrading from PHP 7 to PHP 8

Plan the upgrade, fix breaking changes, automate with Rector, and roll out safely.

  1. Planning a PHP 8 Upgrade — Inventory, test coverage, dependency upgrades and target version choice.
  2. PHP 8.0 Breaking Changes That Bite — String-number comparisons, stricter errors, removed functions and more.
  3. Deprecations in PHP 8.1–8.4 — Dynamic properties, null to non-nullable internal parameters, implicit nullable types and more.
  4. Automating the Upgrade with Rector — Use Rector set lists to upgrade syntax and fix breaking patterns automatically.
  5. Rolling Out PHP 8 in Production — Test, deploy gradually, monitor and keep a rollback path.

7. Performance on PHP 7

Get the most out of PHP 7 runtimes before and during an upgrade.

  1. OPcache and Realpath Cache on PHP 7 — Production OPcache settings and common misconfigurations.
  2. Profiling Slow Legacy Pages — Find where time goes with profilers and query logs.
  3. Adding Caching to a Legacy App — Introduce APCu, Redis and HTTP caching without large rewrites.

8. Operating Legacy PHP in Production

Containerize, deploy without downtime, monitor and plan the road ahead.

  1. Containerizing a Legacy PHP App — Make the old app reproducible with Docker before changing it further.
  2. Zero-Downtime Deploys for PHP — Atomic release directories, OPcache resets and safe migrations.
  3. Monitoring Legacy PHP Applications — Know when the app is unhealthy with logs, metrics and uptime checks.
  4. A Roadmap Beyond PHP 7 — Turn maintenance into a sustained modernization plan.