1.11.0
Read the article about PHPStan 1.11 on phpstan.org »
Major new features 🚀
- Error identifiers
- A way to categorize reported errors by a stable identifier. Up until now you had to use specific and ever-changing error messages
- Can be used for ignoring specific errors locally with new
@phpstan-ignore
comment (uses current or next line automatically) - Can be used for ignoring specific errors in
ignoreErrors
section of your configuration file (phpstan.neon) - Can be used in output formatters
- Can be seen in PHPStan Pro GUI or in TableErrorFormatter with
-v
- Catalogue with source code links: https://phpstan.org/error-identifiers
- PHPStan Pro Reboot
- A new migration wizard will effortlessly migrate all your
@phpstan-ignore-line
and@phpstan-ignore-next-line
to the new@phpstan-ignore
comment style with error identifiers. The old comment style is dangerous because it ignores all errors, current and future, on that line. - Revamped UI for much more comfortable viewing and browsing of reported errors
- The new UI also lets you browse ignored errors, from
ignoreErrors
, from your baseline and also ignored locally in source code using comments - Streaming errors during launch: You don't have to wait for the analysis to complete, you can see errors as they come in during the analysis
- Support for mapping file paths to the host filesystem when running in Docker or remotely
- Try it out by running PHPStan with
--pro
CLI option
- A new migration wizard will effortlessly migrate all your
- PHPDoc tags describing callable lifecycle:
@param-immediately-invoked-callable
,@param-later-invoked-callable
- Useful for exception analysis (https://phpstan.org/blog/bring-your-exceptions-under-control) and
@phpstan-pure
- Useful for exception analysis (https://phpstan.org/blog/bring-your-exceptions-under-control) and
- PHPDoc tag
@param-closure-this
to describe what$this
is bound to in a passed closure - Two new config options around stricter offset checks in arrays (#3028), #7553, thanks @ttomdewit!
reportPossiblyNonexistentGeneralArrayOffset
reportPossiblyNonexistentConstantArrayOffset
- Learn more in the documentation
Bleeding edge 🔪
- Checking truthiness of
@phpstan-pure
above functions and methods - Check
new
/function call/method call/static method call on a separate line without any side effects even without@phpstan-pure
PHPDoc tag on the declaration side - BetterNoopRule - take advantage of impure points (phpstan/phpstan-src@a647052), #10389
- Run missing type check on
@param-out
(phpstan/phpstan-src@56b2002) - CallToConstructorStatementWithoutSideEffectsRule - report class with no constructor (phpstan/phpstan-src@b116d25)
- Deprecated: returning plain strings as errors, use RuleErrorBuilder
- Deprecated: returning RuleError without identifier (phpstan/phpstan-src@969e6fa)
If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon
:
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more
Improvements 🔧
- Generic RuleErrorBuilder (phpstan/phpstan-src@9a3ed85)
- Deprecate
checkMissingIterableValueType: false
andcheckGenericClassInNonGenericObjectType: false
in favour of ignoring via identifiers (phpstan/phpstan-src@a649981) - Deprecate old NoopRule - replaced by BetterNoopRule in bleeding edge (phpstan/phpstan-src@1090835)
- Allow ignoring errors from CollectedDataNode with local comments (phpstan/phpstan-src@dc3b75a)
- Introduce
new
type (#3050), #9704, thanks @ruudk! - RuleTestCase - fail on PHP warnings, notices etc. (#3030), thanks @janedbal!
- Check duplicate assignment of redeclared promoted readonly properties (#3049), #8101, #9863, #9864, thanks @schlndh!
- Remove line from "nikic/php-parser" error message (#2845), thanks @mvorisek!
- Stub validator - PHPStan classes are known without extra stubs (phpstan/phpstan-src@d004c23)
- Stub validator - PhpParser classes are known without extra stubs (phpstan/phpstan-src@3e498e1)
- CheckstyleErrorFormatter - include error identifier in source attribute (phpstan/phpstan-src@f66cf5b), #1205
- BaselinePhpErrorFormatter - error identifiers in comments (phpstan/phpstan-src@4b32cac)
RuleErrorBuilder::file()
- file path needs to exist (phpstan/phpstan-src@c453f29)- AbstractMethodInNonAbstractClassRule - better error message for enums (phpstan/phpstan-src@b5dd34e)
- Fixed Xdebug spelling (#2746), thanks @derickr!
- Track invalidated
$this
and used variables after invoking closure (#2980) - Support
@phan-
prefixes on recognized PHPDoc tags (#3000), thanks @anomiex! pure-callable
andpure-Closure
PHPDoc types (phpstan/phpstan-src@cdaff5f)highlight_string()
flips side-effects depending on $return (#3021), thanks @staabm!- Improve types for predefined constants (#3054), thanks @zonuexe!
Bugfixes 🐛
- Make
AccessoryNonFalsyStringType::toInteger()
returnIntegerType
instead of non-zero (#3018), #10893, thanks @zonuexe! - Filter scope by non-empty array after foreach regardless of
polluteScopeWithAlwaysIterableForeach
(#3029), #10922, thanks @VincentLanglet! - Preserve large arrays with same keys through union (#3032), #9397, #10080, thanks @schlndh!
- Fix
count($x) > $n === true
negation (#3037), #10952, thanks @rvanvelzen! - Fix NAN not accepting NAN (#3036), #10956, #10297, thanks @rvanvelzen!
- DateTimeInstantiationRule - fix error message for
new
with wrong name case (phpstan/phpstan-src@59ac31a) - Process ConstFetch (phpstan/phpstan-src@b5c63c2)
- Fix
preg_match_all
behaviour with no flags (phpstan/phpstan-src@a856ec7) file_get_contents
is an impure function (phpstan/phpstan-src@2b5b317)- Fix
ClosureType::equals()
(phpstan/phpstan-src@29c35b5) - Use statement result of analysed anonymous class to inform about throw points and impure points (phpstan/phpstan-src@70a75f6)
- Filter out implicit throw points from callables when
exceptions.implicitThrows: false
(#3016), thanks @janedbal! - Fix
ConstantArrayType::hasOffsetValueType()
for offset union type where all types are valid (phpstan/phpstan-src@26e949b) non-empty-list
always has offset 0 (phpstan/phpstan-src@f4d1d48)- Narrow to
non-empty-string
/non-falsey-string
aftermb_strlen()
(#3038), thanks @staabm! - Implement
Type::isOffsetAccessLegal()
to detect offset access that crashes even inisset()
(#3045), #8393, #10926, thanks @rajyan! - Specify types on
match()
condition correctly (#3053), #10974, #9694, thanks @rvanvelzen! json_decode
with force array flag: subtract all objects, not just stdClass (#3052), thanks @rajyan!- Fix
strlen($x) > $n === true
negation (#3040), thanks @staabm! - Support multi-byte string function variants (#3039), thanks @staabm!
- Final scope from
Continue_
points should not be used forwhile (true)
(#3057), #10980, thanks @greew! - Fix enum performance problem (#3062, #3060), #10979, thanks @staabm!
- NULL and null as a property default value are treated differently when overriding a parent property (#3063), #10987, thanks @staabm!
Function signature fixes 🤖
- Make the url key of metadata returned by
stream_get_meta_data()
optional (#3024), #10887, thanks @hirokinoue! - Narrow
Closure::bind
$newScope
param (#2817), thanks @mvorisek! - Infer object type mysqli_fetch_object (#2675) (#2675), thanks @staabm!
- Fix
Imagick::identifyImage()
return type (#3017), thanks @SVillette!
Internals 🔍
- Clean up old identifiers and metadata (phpstan/phpstan-src@c476a86)
- Delete StatementOrderVisitor that is no longer needed (phpstan/phpstan-src@017d321)
- Introduce
ClassReflection::getClassTypeDescription()
(phpstan/phpstan-src@dec9e43) - Fix classname typo in tests (#2461), thanks @szepeviktor!
- Fix various typos (#2463), thanks @szepeviktor!
- Added text regarding patch issues during installation (#2670), thanks @mt-satak!
- Fix typo in ArgumentsNormalizer (#2705), thanks @mad-briller!
- Rich PHPDoc for ExceptionTypeResolver (phpstan/phpstan-src@e7ab4f7)
- Hide internal commands (#2833), thanks @rvanvelzen!
- Test invalidated object in static closure (#2981), thanks @staabm!
- PHPDoc: address multiple variables defined in one @param (#3001), thanks @Muqsit!
- Do not assume every contributor uses PhpStorm (phpstan/phpstan-src@d1834e6)
- TypeInferenceTestCase: ability to disable implicit throws (#3015), thanks @janedbal!
- Slightly reduce comparing and calling methods for trivial optimizations (#3004), #10926, thanks @zonuexe!
- AnalyserResultFinalizer - DRY of running CollectedDataNode rules (phpstan/phpstan-src@38e2c96)
- Introduce LocalIgnoresProcessor (phpstan/phpstan-src@d026655)
- Introduce
RuleErrorBuilder::treatPhpDocTypesAsCertainTip()
for a bit more DRYness (#3035), thanks @axlon! - Make ResultCacheEndToEndTest pass level 9 (#3055), #10977, thanks @AJenbo!
- ClassReflection - cache enum cases (phpstan/phpstan-src@39ce042), #10979