1.6.0
Read the article about PHPStan 1.6.0 »
Major new features 🚀
- Conditonal return types (pull requests), #3853, big thanks to @rvanvelzen!
- Allows return types in the form of
@return ($i is positive-int ? non-empty-array : array)(don't forget the parentheses!) - Another possible form is with generic
@templatetags:@return (T is positive-int ? non-empty-array : array)
- Allows return types in the form of
int-mask<...>andint-mask-of<...>types (#1166), thanks @rvanvelzen!- Allow global constants as PHPDoc types (#1163), thanks @rvanvelzen!
- Update
php-8-stubsto know about PHP 8.1 function signature changes, #7017, #6448 - Make
isset()and null-coalesce (??) operators consistent with each other (#1223), thanks @rajyan!
Bleeding edge 🔪
- Fully static reflection engine
- After feedback is gathered and processed, this will be enabled for everyone later in PHPStan 1.x release cycle.
- Lower memory consumption thanks to breaking up of reference cycles
- This is a BC break for rules that use
'parent','next', and'previous'node attributes. Learn more » - In testing the memory consumption was reduced by 50–70 %.
- This is a BC break for rules that use
- ArrayUnpackingRule (level 3) (#856), thanks @canvural!
- Rules for checking direct calls to
__construct()(level 2) (#1208), #7022, thanks @muno92! checkMissingIterableValueType: falseno longer does anything (phpstan/phpstan-src@50d0c8e)
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 🔧
- EnumCaseObjectType cannot be compared in a numeric sense (phpstan/phpstan-src@f7d80d6), #7052
- StatementResult is part of BC promise (phpstan/phpstan-src@796c9d5), #7075
Bugfixes 🐛
- Fix uncaught LogicException from phpdoc-parser (phpstan/phpstan-src@b95949a), #7030
- Fix issue with dynamic properties (#1237), #3171, thanks @rajyan!
- Class with final doesn't mean dynamic property is prohibited (#1238), thanks @rajyan!
- Fix
isset()with multiple arguments (#1240), #3601, thanks @rajyan! - Match expression
isset()fix (phpstan/phpstan-src@3c7d9c8), #7095
Function signature fixes 🤖
- Fix
json_decodeerror return type (#1235), thanks @herndlm! - Add return type extension for
mb_strlen(#1211), thanks @fluffycondor! db2_last_insert_idmay return NULL (#1214), thanks @morozov!- Fix
SimpleXMLElement::addChildsignature (#1215), thanks @szepeviktor! - Make the type signatures of some hash functions more specific (#1224), thanks @oliverklee!
- Do benevolent union for
SimpleXMLElement::children()(phpstan/phpstan-src@3a2f105)