Fixes & guides

A tested PHP upgrade workflow with Rector, PHPStan and your test suite

Upgrade a PHP application one version at a time: pin the baseline, let Rector rewrite syntax, let PHPStan find what Rector cannot, and prove it with tests before you switch runtimes.

On this page
  1. Before you start
  2. Step 1: upgrade dependencies first
  3. Step 2: configure Rector for one version step
  4. Step 3: dry run, review, apply
  5. Step 4: run PHPStan against the target version
  6. Step 5: run the tests with every notice visible
  7. Step 6: switch the runtime
  8. What Rector will not catch

Rector rewrites PHP code automatically: it can add types, replace removed functions and adopt new syntax. It does not know your business logic, so the workflow below wraps it in checks. It works for any jump, from PHP 7.4 to 8.6.

Before you start

  • Tests on the current version must pass. If coverage is thin, write characterization tests for the most important paths first: tests that assert today’s behaviour, even if it is odd.
  • Pin the current runtime in CI, then add a second job for the target version that is allowed to fail.
  • Generate your list of version-specific changes with the PHP upgrade checklist. Keep it open; you will tick items off as you go.

Step 1: upgrade dependencies first

composer require php:^8.4 --no-update
composer update --with-all-dependencies --dry-run

Old packages are the most common blocker. Upgrade framework majors separately from the PHP upgrade where you can, and read each package’s changelog for breaking changes.

Step 2: configure Rector for one version step

composer require --dev rector/rector
<?php
// rector.php
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
    ->withPhpSets(php81: true);   // one step at a time: php80, then php81, ...

withPhpSets() applies every rule up to that version. Move one minor version per pull request when the jump is large; the diffs stay reviewable.

Step 3: dry run, review, apply

vendor/bin/rector process --dry-run
vendor/bin/rector process

Read the diff like any pull request. Typical changes: constructor property promotion, str_contains() instead of strpos() !== false, explicit nullable types (?Foo $x = null, required in 8.4), and match instead of simple switch blocks.

Step 4: run PHPStan against the target version

Set phpVersion in phpstan.neon to the target and run it. It finds calls to removed functions, wrong argument counts and signature changes that Rector did not touch. If the existing code produces a lot of noise, start from a baseline.

Step 5: run the tests with every notice visible

php -d error_reporting=-1 -d display_errors=1 vendor/bin/phpunit

Fix deprecations now, not later: today’s deprecation is the next version’s error. In PHPUnit 10+, use failOnDeprecation="true" and displayDetailsOnTestsThatTriggerDeprecations="true" in phpunit.xml.

Step 6: switch the runtime

  1. Deploy to staging on the new PHP version, with the same extensions (php -m) and ini settings.
  2. Watch the error log under real traffic for a day.
  3. Switch production, keeping the old runtime available for a quick rollback.
  4. Remove the old version from CI once you are confident.

What Rector will not catch

Behaviour changes with the same syntax: string-to-number comparisons in 8.0, locale-insensitive strtolower() in 8.2, stricter session cookie defaults in 8.6. These are why the checklist and the tests matter more than the automated diff.

Found a mistake or something out of date? Tell us and we will fix it. See our editorial policy.

A good place to start

What are you working on?

Tools, guides, PHP versions and the archive.

ToolJSON ↔ PHP arrayConvert JSON to a PHP array literal with short or array() syntax, or turn a PHP array back into JSON. Runs in your browser; nothing is uploaded.ToolSerialized data inspectorRead PHP serialized strings as a tree, find wrong string lengths after a search-and-replace, and rebuild them with correct byte counts. Parsed safely in your browser.ToolComposer constraint testerSee exactly which versions a Composer constraint such as ^2.1, ~1.4 or >=8.1 <8.4 allows, in plain English, and test versions against it.ToolPHP date() format builderBuild a PHP date() or DateTime::format() string with a live preview in any time zone, plus a reference for every format character.ToolPHP upgrade checklistPick your current and target PHP versions and get every breaking change, deprecation and tooling step in between, as a checklist you can copy.GuideAllowed memory size exhaustedWhat PHP's memory_limit fatal error means, how to tell a real leak from a big job, and fixes for the usual causes: loading whole tables, unbounded arrays, Composer and recursion.GuideComposer dependency conflictsA step-by-step way to read Composer's conflict output, find the package that is blocking you, and fix it without --ignore-platform-reqs or deleting the lock file.Guidecomposer install vs updatecomposer install reproduces composer.lock; composer update rewrites it. Here is what each command does, when to use which, and a safe production deploy routine.GuideComposer uses the wrong PHP versionComposer says "your php version (8.1.x) does not satisfy that requirement" when your server runs 8.3? The cause is usually the CLI binary, config.platform.php, or platform_check.php.GuideEloquent N+1 queriesHow to spot N+1 queries in Laravel, fix them with eager loading, withCount() and constrained loads, and make Laravel throw an exception the next time one slips in.GuideHeaders already sentThe warning names the file and line that produced output. Here is how to read it, the five usual culprits (BOM, whitespace, echo, warnings, closing tags) and fixes that do not just hide it.GuideWriting a talk proposalWhat reviewers look for in a call-for-papers submission: a specific title, an abstract for attendees, notes for the committee, and a talk-sized idea. With a worked example and a checklist.GuideLaravel queue jobs not runningJobs dispatched but never processed, stuck in the jobs table, or running old code? Work through the connection, the queue name, the worker, failed jobs and deploy restarts.PHP versionsWhat's new in PHP 8.4PHP 8.4 (released 21 November 2024) brought property hooks, public private(set) visibility, new without parentheses, lazy objects, an HTML5 DOM parser and array_find(). Plus the deprecations that matter.PHP versionsWhat's new in PHP 8.5PHP 8.5 (released 20 November 2025) added the |> pipe operator, a standards-compliant URI extension, clone() with property overrides, #[\NoDiscard] and array_first()/array_last().PHP versionsWhat's new in PHP 8.6PHP 8.6 was released on 19 November 2026. Partial function application, clamp(), readonly property defaults, Io\Poll and Time\Duration, plus the session and ValueError changes to check before upgrading.GuidePHP array to JSONWhy json_encode() sometimes gives you an object instead of a list, how to keep floats and slashes intact, and how to catch the silent false that malformed UTF-8 returns.GuideDuplicate webhooks in PHPWebhook providers retry, so the same event can arrive twice. Verify the signature, record the event ID with a unique key, answer fast and process in a queue: a pattern that works in plain PHP, Laravel and Symfony.GuidePHPStan baseline for legacy codeGenerate a PHPStan baseline, stop new errors from getting in, then raise the level step by step. A tested routine for old PHP codebases.GuidePSR-4 autoloadingHow PSR-4 maps namespaces to folders, how to configure it in composer.json, and why "Class not found" happens: case, typos, a stale autoloader or a namespace that does not match the path.GuideSerialized data broken after search-replaceChanging a domain name with SQL REPLACE() or sed corrupts PHP serialized strings because their byte lengths no longer match. Here is how to spot it and repair it safely.GuideUpgrade PHP with RectorUpgrade a PHP application one version at a time: pin the baseline, let Rector rewrite syntax, let PHPStan find what Rector cannot, and prove it with tests before you switch runtimes.PHP versionsSupported PHP versionsRelease, active support and end-of-life dates for every PHP version.ArchiveSunshinePHP talk archive 2013–2020Talk titles and speakers from eight years of the Miami PHP conference.ArchiveSpeaker indexEveryone who spoke at SunshinePHP, A to Z.