Back to Blog
PHPStan 2.3 on a Laravel App: Faster Runs, Unused Variable Checks, and What I'd Turn On
PHPStan 2.3.0 shipped on October 6 with a big speed jump, smarter result caching, and new unused variable rules behind bleeding edge. Here is what changes for a Laravel project running Larastan, and what I would enable first.
Back
Engineering
Table of contents
PHPStan 2.3.0 came out on October 6, 2026. The release notes say it fixes 75 issues, but the headline is speed. The PHPStan blog's benchmark of WordPress core went from about 60 seconds on PHPStan 2.1.33 (December 2025) to under 8 seconds on 2.3.0.
PHPStan is now on 2.3.7 (released 19 November 2026). The 2.3 line is what matters for Laravel teams: Larastan has officially embraced it since 3.13.0.
That is one codebase on one machine, so I would not promise the same number on your Laravel app. Still, it is a big enough change that it is worth an upgrade this week, and a few of the new checks are the kind that catch real bugs.
Quick Answer
Update PHPStan and Larastan together, then run your normal analysis.
bash
composer update phpstan/phpstan larastan/larastan --with-all-dependencies
vendor/bin/phpstan diagnose
vendor/bin/phpstan analyseThe speedup needs no config. The new rules (unused variables, better generics and closure inference) only run if you include bleeding edge, so the upgrade itself should not flood you with new errors. Turn bleeding edge on in a separate commit, where you can see exactly what it reports.
Where the speed comes from
There are two pieces.
The first is ordinary optimization work across the year. In the blog post's table, WordPress analysis without any native help dropped from 60.51 seconds (2.1.33) to 19.47 seconds (2.3.0). The 2.3 release also rewrites the core engine into a single pass, so expressions are no longer processed several times over. That rewrite is what made the new inference features cheap enough to ship.
The second is PHPStan Turbo, an optional PHP extension that reimplements hot parts of PHPStan in C++. It arrived in 2.2.6 in July. With Turbo on, the same WordPress run takes 7.93 seconds. The blog puts Turbo at almost 60% faster than the no-Turbo baseline. The Turbo README gives a smaller number (about 25% on PHPStan's own single-threaded self-analysis), so the gain clearly depends on what you analyse.
You probably already have Turbo. The phpstan/phpstan Composer package ships prebuilt binaries for Linux (glibc and musl, x86_64 and arm64), macOS on arm64, and Windows x86_64, for PHP 8.3 and newer, and PHPStan loads the matching one by itself. If you run the downloaded phpstan.phar outside Composer, the README says to install it with pie install phpstan/turbo.
Two details I like from the README. vendor/bin/phpstan diagnose tells you whether Turbo is active. And if the extension version does not match your PHPStan version, PHPStan prints a note and runs without it, so a stale extension can only cost speed, not change results.
If your CI image still runs PHP 8.2, you will not get the Turbo binaries. That is a good excuse to move CI to the PHP version you actually deploy.
The result cache matters more than the cold run
Most of my PHPStan runs are not full runs. They are "I changed four files, check again." The blog shows warm result cache numbers on Drupal, which is larger than WordPress (22 seconds for a full run):
- Nothing changed: 1.58 seconds
- 10 files changed: 2.84 seconds
- About 10% of files changed: 6.21 seconds
The 2.3 change here is about invalidation. The blog says PHPStan used to throw away the whole cache when any Composer dependency was updated, and now it tracks which analysed files depend on which installed packages, so only the affected files get re-analysed.
One caution. The result cache docs page still lists composer.lock hashes as one of the values that triggers a full re-analysis. The docs may simply lag the release, but I would check it on my own project before I count on it. Run with -vv and PHPStan tells you whether it used the cache and why not.
If your CI does not cache PHPStan's result yet, this is the cheapest win in the whole release. The docs show the GitHub Actions setup: set tmpDir inside your workspace, restore the cache before running PHPStan, and save it with a unique key afterwards, even when the build fails.
neon
parameters:
tmpDir: tmpUnused variable detection (bleeding edge)
This is the part I care about most on Laravel code. PHPStan never really checked for unused variables before. Now, with bleeding edge on, it reports several kinds:
variable.unused: assigned but never readassign.unused: the value is never read before the function endsassign.overwritten: overwritten before anyone reads itassign.redundant: assigned a value it already hasassign.unusedFlow: looks used, but the value never ends up anywhere
It also covers array keys that are never read, foreach keys and values, catch variables, closure use variables, and unused parameters on functions and private methods.
The blog's example is almost too familiar. You compute a TTL, then forget to pass it:
php
function cacheReport(Cache $cache, Report $report): void
{
$ttl = 3600;
$cache->save($report->getId(), $report, $ttl);
$ttl = 600;
$cache->save($report->getId() . '-summary', $report->getSummary());
}PHPStan flags the second $ttl with assign.unused. Nothing crashes, the summary just gets the default cache lifetime, and you find out weeks later. In a Laravel app I can picture the same thing with a $delay that never reaches ->delay(), or a $timeout that never reaches Http::timeout().
Note what is not in the list: unused parameters on public methods. So controllers and interface implementations that ignore a Request $request argument should not light up. Private helpers will.
Generics and closures get smarter (also bleeding edge)
The other bleeding edge features are about inference, and they will mostly show up as fewer annoying errors rather than new ones.
PHPStan used to generalize scalars in generics, so doFoo(1) with a @template T came back as int, not 1. In 2.3 it analyses how a new Collection(...) is used afterwards and narrows the template type from that. Empty collections that later receive ints become Collection<int> instead of an awkward never. The blog says this closed 17 related issues.
Closures stored in variables now get their parameter types inferred from where they are passed. static variables get typed from the assignments in the function body instead of falling back to mixed.
For Laravel, where half the code is closures handed to collection methods, queues, and routes, I expect this to be the quiet improvement that removes some @var and @param noise. I have not measured that on a real project yet, so treat it as a guess.
To try all of this, add bleeding edge to your phpstan.neon:
neon
includes:
- vendor/larastan/larastan/extension.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neonThe PHPStan docs are clear that bleeding edge has no backwards compatibility promise. Reported errors can change between minor versions. I would turn it on locally, look at what it finds, and decide per rule. If the new errors are mostly noise in older code, ignore them by identifier or regenerate your baseline instead of leaving bleeding edge off entirely.
Larastan
Larastan 3.12.3 was released on 4 October 2026 (UTC). Larastan 3.14.0 (3 November 2026) requires phpstan/phpstan ^2.3.0 in composer.json, and 3.15.0 (11 November 2026) requires ^2.3.5. That means current Larastan officially supports PHPStan 2.3: you are no longer depending on a permissive ^2.2.14 constraint and hoping Composer picks a compatible minor.
Update Larastan to at least 3.14.0 when you move to PHPStan 2.3, and to 3.15.0 if you want the latest Larastan fixes. If something odd shows up (for example around Eloquent builder types), check the Larastan issue tracker before you blame your code.
If you use other official extensions, update them at the same time. phpstan-strict-rules, phpstan-symfony, and phpstan-phpunit all shipped 2.1.0 alongside PHPStan 2.3.0. The strict rules release makes one of the foreach overwrite checks less noisy.
My take
This is the first PHPStan release in a while where I would tell a team to upgrade for the experience, not just the bug fixes. Fast static analysis changes behaviour. When it takes eight seconds, people run it before they push. When it takes a minute, they wait for CI.
What I would do, in order:
- Upgrade PHPStan and Larastan, run
diagnose, and confirm Turbo is active. - Add the result cache to CI if it is not there.
- Turn on bleeding edge in a separate change and read every unused variable report. Some will be dead code. A few will be real bugs like the TTL example.
I would not rush the generics changes into a big legacy codebase on day one. They are good changes, but bleeding edge means the behaviour can still move.
Sources
Facts checked on 20 November 2026.
- PHPStan 2.3: Leap in Performance, Generics Improvements, Detecting Unused Variables, and More! (official blog)
- PHPStan 2.3.0 release notes
- PHPStan 2.3.7 release notes (November 19, 2026)
- PHPStan Turbo extension README
- PHPStan docs: Result Cache
- PHPStan docs: What is bleeding edge?
- Larastan v3.12.3 release (October 4, 2026 UTC)
- Larastan v3.14.0 release (November 3, 2026)
- Larastan v3.15.0 release (November 11, 2026)
- Larastan
composer.jsonat v3.14.0 - Larastan
composer.jsonat v3.15.0
Comments
No comments yet
Loading comments...