What do PHPStan's Bleeding Edge and the phpstan-strict-rules extension each add beyond rule levels, and how do you enable them?
answer
- preview of the next major
- phar://phpstan.phar/conf/bleedingEdge.neon
- strict-rules: opinionated extra checks
- extension-installer enables everything
- include rules.neon by hand to pick
basics
~10 sBleeding Edge, enabled by including phar://phpstan.phar/conf/bleedingEdge.neon, turns on the next major version's rules and behaviour early; phpstan-strict-rules is an opinionated extension of extra checks, enabled through phpstan/extension-installer or by including its rules.neon.
solid answer
~50 sBoth sit outside the numbered levels and can be combined with any of them. **Bleeding Edge** is a set of feature toggles in `conf/bleedingEdge.neon` that switches on rules and behaviour planned for the next major PHPStan release, inside the current stable one. You enable it with `includes: - phar://phpstan.phar/conf/bleedingEdge.neon`; the payoff is less work at the next major, which is why the 2.0 upgrade guide said to get green on the latest 1.12 with Bleeding Edge first. **phpstan-strict-rules** is a separate Composer package of opinionated, defensive rules; it also flips config defaults such as `polluteScopeWithLoopInitialAssignments` to false and `checkFunctionNameCase` to true. Install it with `composer require --dev phpstan/phpstan-strict-rules`; with `phpstan/extension-installer` it is enabled automatically, otherwise you include its `rules.neon`. The installer always enables everything an extension offers, so teams that want only some rules include files by hand.
code
yaml · 9 linesincludes:
- phar://phpstan.phar/conf/bleedingEdge.neon
# only when phpstan/extension-installer is NOT used:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
level: 8
paths:
- srcgo deeper
Know that there is extra strictness outside the numbered levels: Bleeding Edge and the phpstan-strict-rules extension.
Show how each is enabled: the bleedingEdge.neon include, and strict-rules via extension-installer or a manual rules.neon include.
Explain feature toggles and the upgrade benefit of Bleeding Edge, strict-rules' flipped defaults, and why teams skip the installer to select rules.
Decide when a team can afford Bleeding Edge's moving target and which opinionated rules become organisation policy versus per-project choice.
## Two ways to go past the levels Rule levels 0 to 10 are PHPStan's main strictness dial, but they are not the only one. Two opt-in additions can be used at **any** level: | | Bleeding Edge | phpstan-strict-rules | |---|---|---| | What it is | feature toggles shipped inside PHPStan itself | a separate Composer package | | Purpose | preview of the next major version's rules and behaviour | extra, opinionated rules for defensive code | | Enable | `includes: - phar://phpstan.phar/conf/bleedingEdge.neon` | `composer require --dev phpstan/phpstan-strict-rules`, then installer or manual include | | Changes over time | yes, toggles are added in minor releases | with the extension's own releases | | Becomes default | at the next major version | never; always opt-in | ## Bleeding Edge PHPStan's backward-compatibility promise says a minor or patch release does not look for new categories of errors: new rules arrive only in major versions, and also in Bleeding Edge. They are developed behind **feature toggles** that are switched off by default. `conf/bleedingEdge.neon` sets those toggles to `true`, for example `bleedingEdge: true`, `checkPrintfParameterTypes`, `reportTooWideBool`, `unnecessaryNullCoalesce` in 2.2. - **Enable** it by adding `phar://phpstan.phar/conf/bleedingEdge.neon` to `includes` in `phpstan.neon`. - **Benefit**: new rules and bug fixes reach you months before the next major, and when that major ships most of its new errors are already fixed in your code. - **Cost**: a minor PHPStan update can add errors to a Bleeding Edge build, because new toggles can arrive in minor releases. Teams that want predictable builds pin the PHPStan version and update deliberately. - **Upgrade path**: the 2.0 upgrade guide recommended reaching a green build on the latest 1.12 with Bleeding Edge and `phpstan-deprecation-rules` enabled, then bumping to `^2.0`. For example, 2.0 made "always true" conditions always reported, which in 1.x only phpstan-strict-rules did. ## phpstan-strict-rules `phpstan/phpstan-strict-rules` is an official extension for teams that want extremely defensive, strongly typed code. It works in two ways: 1. It **adds rules** of its own, which PHPStan's rule-levels page describes as revolving around strictly and strongly typed code with no loose casting. 2. It **flips config defaults** documented in PHPStan's config reference, such as: - `polluteScopeWithLoopInitialAssignments`, `polluteScopeWithAlwaysIterableForeach` and `polluteScopeWithBlock` to `false`, so variables set only inside a loop header or a block cannot be read afterwards; - `checkFunctionNameCase` and `checkInternalClassCaseSensitivity` to `true`, reporting `STRLEN()` or `datetime` spelled in the wrong case; - `reportMaybesInMethodSignatures`, `reportMaybesInPropertyPhpDocTypes` and `reportStaticMethodSignatures` to `true`, reporting partial variance violations rather than only complete ones. Because it is opinionated, some rules may not fit a codebase. That is why the enabling mechanism matters. ## Enabling extensions: installer or includes - **`phpstan/extension-installer`** is a Composer plugin. Each installed extension declares its config files in its `composer.json` `extra` section; the plugin generates a class listing them, and PHPStan includes them automatically at startup. `composer require --dev phpstan/extension-installer phpstan/phpstan-strict-rules` is then all you need. - The installer **always enables all of an extension's functionality**. To use only part of strict-rules, or only `extension.neon` but not `rules.neon` from a framework extension, skip the installer and include the chosen files by hand. - Do not do both: if a file is included manually and by the installer, PHPStan stops with a *files are included multiple times* error and tells you to remove the manual include. ## Seeing what you are opting into Because Bleeding Edge is just a NEON file, you can read exactly what it turns on: every toggle is listed in `conf/bleedingEdge.neon` in PHPStan's source, and new toggles are mentioned in the release notes. In 2.2 the list includes toggles such as `checkPrintfParameterTypes`, `reportTooWideBool`, `unnecessaryNullCoalesce` and `checkImportedClassNameCase`. Reading the diff of that file between two PHPStan versions tells you what a Bleeding Edge build will newly report after an upgrade. strict-rules is equally inspectable: its effect on configuration is documented option by option in PHPStan's config reference, where each affected key notes "strict-rules sets it to" the stricter value. PHPStan's baseline documentation also suggests enabling strict-rules together with a baseline, so its rules apply to new code without first fixing every existing violation. ## Choosing and rolling out - Turn on **Bleeding Edge** early on a healthy codebase; it is the cheapest way to make the next major upgrade uneventful. - Add **strict-rules** after the level you target is green, and review its errors as a team, because some of them encode style decisions rather than bugs. - Both can be adopted gradually with the same tools used for raising levels, and neither replaces moving up the numbered levels.
- Why might a Bleeding Edge build turn red after a PHPStan minor update when a normal build stays green?New checks are added behind feature toggles in minor releases and switched on only in `bleedingEdge.neon`. Bleeding Edge users get them immediately, so a minor update can report new errors. Pinning the PHPStan version and updating deliberately keeps that under control.
- PHPStan refuses to start with 'files are included multiple times' after adding extension-installer; why?The installer already includes each installed extension's config files automatically. If phpstan.neon still includes the same `rules.neon` or `extension.neon` by hand, the file is loaded twice. Remove the manual include, or remove the installer and keep the manual includes.
saying these in an interview costs you the question
- Bleeding Edge means running an unreleased development build of PHPStan
- strict-rules is the same thing as level max
- extension-installer lets you pick individual rules from an extension
- Bleeding Edge only works at level 10
- Including an extension both manually and via the installer is harmless