1.8.3
This release fixes 76 issues! :tada:
Improvements 🔧
- Added
non-falsy-string
(truthy-string
) type (#1542, #1660, #1661, #1662), #5317, #5370, #7199, thanks @staabm! - New configuration option:
checkImplicitMixed
(#1645), thanks @MartinMystikJonas! - Support constant string-unions in
substr()
(#1532), #7663, thanks @staabm! - Tagged unions preparation (#1548), #5232, #7511, #7224, #6997, #6556, #6181, #5743, #4708, #3821, #2911, #7156, #6728, #6364, #5758
- Tagged unions (#1547), #6469, #3801, #6599
- Added error message to impossible instanceof rule to warn when comparing a trait (#1570), thanks @mad-briller!
- Implement
ltrim()
return type extension to supportclass-string
(#1597), #7483, thanks @staabm! - Improve type inference from conditional return type (#1604), thanks @rvanvelzen!
- Optimization: ArrayType::setOffsetValueType() - generalize key + item type if it goes over a threshold (phpstan/phpstan-src@24aee60, phpstan/phpstan-src@10ba3c6)
- Optimization: ConstantArrayTypeBuilder - generalize key types and value types in degraded general array (phpstan/phpstan-src@dbdcb81)
- Make
@psalm-readonly-allow-private-mutation
as alias of@readonly
(#1609), #7774, thanks @zonuexe! - Implement
gettype()
inference in TypeSpecifier (#1611), #6901, thanks @staabm! - Use argument types as parameter types for inline closures (#7798) (#1628), #7798, thanks @leongersen!
- Optimization: inline calls in TrinaryLogic to reduce method call overhead (#1563), thanks @staabm!
- Handle the expression
expr & number
for positive numbers (#1629), thanks @thg2k! - Add type specifying extension for
ctype_digit
(#1635), thanks @fluffycondor! array_flip()
for constant arrays (phpstan/phpstan-src@a6cec39)array_filter()
for constant arrays (phpstan/phpstan-src@771b860)array_intersect_key()
for constant arrays (phpstan/phpstan-src@a96cdf2)- Enfore optional parameters in callable types (#1354), #7320, thanks @rvanvelzen!
- Optimization: match/enum performance (phpstan/phpstan-src@092ef3b)
- Optimization: TrinaryLogic - lazy evaluation methods (phpstan/phpstan-src@f8f6e2a)
Bugfixes 🐛
- Support
ConstantArrayType
callables with union values (#1529), #2343, thanks @herndlm! - PHPDoc readonly rules do not report for native readonly props (#1521), #7648, thanks @herndlm!
- Fix error for custom autoloaders calling
eval()
(phpstan/phpstan-src@058d739), #7647 - Remove undefined constants from scope (#1534), thanks @herndlm!
- Fixed double reporting of promoted properties (#1533), #7662, thanks @mad-briller!
- Fixed extracting PHP 8 stubs (phpstan/php-8-stubs@363a282), #7676
- Remove old
pg_*
functions with multiple variants from signature map on PHP 8.1 (phpstan/phpstan-src@8128a63), #7138 - Fix ObjectType resolving inside bound Closure (#1543), #7675, thanks @herndlm!
- Fix
in_array
non-empty-array type specification (#1545), #7684, thanks @herndlm! - Fix incorrect mixed template type for impossible union template type intersection (#1546), #7688, thanks @rvanvelzen!
- Improve
ConstantArrayType::unsetOffset
(#1537), #5223, thanks @herndlm! - Fix incorrect incomplete match error for
treatPhpDocTypesAsCertain: false
(#1560), #7622, thanks @rvanvelzen! - Fix variable certainty after exhaustive switch (#1561), #1016, thanks @rvanvelzen!
- Fix resolving variants for union type methods (#1574), #7593, #6946, #5754, thanks @rvanvelzen!
- Fix assigning arbitrary expressions in foreach key (#1582), #7737, thanks @rvanvelzen!
- Assume offset value set was successful for further analysis (phpstan/phpstan-src@1537424), #7469, #3391, #7417
- Support removing
class-string
s fromGenericClassStringType
(#1590), #7698, thanks @staabm! - Fix
Array_
expr type resolving with unpacked array items (#1586), #7724, thanks @herndlm! - Fix
Array_
expr type resolving with unpacked constant array items (#1619), #7776, thanks @herndlm! - ArrayDimFetch: assign vs. narrowing a type (phpstan/phpstan-src@229df9b)
- Discover BetterReflection sources using PSR-4 (phpstan/phpstan-src@8ab002a)
- Fix internal error with
json_decode()
without arguments (phpstan/phpstan-src@bf6d4c0), #7762 - array_key_exists - fix for AST-based offset (phpstan/phpstan-src@8613169), #7763
- Escape control characters in
ConstantStringType::describe()
(#1612), thanks @rvanvelzen! - Fix offset access + key-of template type combination (#1623), #7788, thanks @rvanvelzen!
- Fix array_search extension incorrectly returning null (#1633), #7809, thanks @herndlm!
- Specify existent offset with key variable when entering foreach (phpstan/phpstan-src@14592dd)
- Generalize file and dir magic constants (phpstan/phpstan-src@f09b288)
- Unsetting an offset should remove
non-empty-array
(phpstan/phpstan-src@32353a9) - Narrow
$data[$key]
after specifying$key
(phpstan/phpstan-src@46a8f32), #6008 - Fix PreInc/PreDec of NeverType (#1641), #7044, #3277, thanks @herndlm!
- Consider
MixedType
explicitness inMethodParameterComparisonHelper::isTypeCompatible
(#1491), #7415, thanks @herndlm! - Do not consider mixed explicitness for parameter contravariance (#1648), thanks @herndlm!
- serialize/unserialize is not allowed in enum (#1643), #7837, thanks @staabm!
- Fixed generalizing arrays in scope, simplified offset unset in
ConstantArrayType
(phpstan/phpstan-src@6173110), #6013, #2851, #6008 - Fix NeverType for more operators (#1649), thanks @staabm!
- support length parameter in
sscanf()
(#1593), thanks @staabm! - sscanf: allow nulls in returned array (#1577), #7735, thanks @staabm!
- Fixed comparison of empty array with a scalar type (#1650), thanks @staabm!
- Fix
sscanf()
inference with regex format patterns (#1576), #7563, #7764, thanks @staabm! - Resources may be opened or closed (#1617), #5845, thanks @staabm!
- Fix ConstantArrayType intersecting with HasOffsetValueType (phpstan/phpstan-src@9c49d4c)
- Take subtracted type into account in
MixedType
(#1656), thanks @staabm! - Fix resolving mixed + array (#1579), #7492, #6783, #3872, thanks @staabm!
- Fixed non-falsy-string inference with '0' (#1658), #7877, #7881, thanks @staabm!
- Fix numeric-string negated intersection (#1639), #7814, thanks @fluffycondor!
- Make
PHPStan\dumpType
pure (#1665), #7803, thanks @rvanvelzen! - Fix wrong message - Instanceof between Xxx and string (#1669), #5728, thanks @lulco!
- Fix unset bug (phpstan/phpstan-src@024738f), #6170
- Make ArrayKeyExistsFunctionTypeSpecifyingExtension understand an empty array (phpstan/phpstan-src@c057aa9)
Function signature fixes 🤖
Imagick::queryFontMetrics
more specific return type (#1530), thanks @MartkCz!Imagick::roundCornersImage
correct naming and optional params (#1531), thanks @MartkCz!str_split
returns an empty array since PHP 8.2 (#1544), thanks @herndlm!XmlReader::next|read()
has side-effects (#1551), #5920, thanks @staabm!- Reflection:
getName()
returns anon-empty-string
(#1599), #7056, thanks @staabm! - More precise
ord()
signature (#1620), thanks @thg2k! - More specific type for
port
component of 'parse_url()
(#1622), thanks @thg2k! - Allow null as second parameter for json_decode (#1672), thanks @webmaster777!
- Encoding functions returns non-empty-string (#1664), thanks @staabm!
Internals 🔍
- HasOffsetType - create only for ConstantIntegerType|ConstantStringType (phpstan/phpstan-src@0a2fc63)
- Simplify
non-empty-array
removal inarray_push
/array_unshift
(#1552), thanks @herndlm! - Fix
VirtualNode::getType()
returning an incorrect value for ClassConstantsNode and MethodReturnStatementsNode (#1568), thanks @Muqsit! - Add return type stub for
SimpleXMLElement::asXML
(#1606), thanks @herndlm! - Simplify TypeSpecifier (#1613), thanks @staabm!
- Avoid unnecessary intersection in
MutatingScope::filterBySpecifiedTypes
(#1536), thanks @herndlm! - Make
IntegerRangeType
constructor private (#1624), #7803, thanks @herndlm! - Remove
jean85/pretty-package-versions
dependency (#1607), thanks @herndlm! - Require
brianium/paratest
^6.5 to fix PHP 8.2 deprecation notices (#1631), thanks @herndlm! - Replace pickArrays method in array_search extension with getAnyArrays helper (#1632), thanks @herndlm!
- Intersect HasOffsetValue type only with possible arrays (#1634), thanks @herndlm!
- Avoid benevolent union behaviour for more type methods (#1644), thanks @herndlm!
- Use isArray instead of array supertype checks (#1634), thanks @herndlm!
- Use isString instead of string supertype checks (#1634), thanks @herndlm!
- Make MutatingScope::invalidateMethodsOnExpression() private (phpstan/phpstan-src@f3fe245)
- Deprecate
TypeUtils::containsCallable()
(#1667), thanks @herndlm! - Use TypeUtils::getOldConstantArrays in array_pop and array_shift extensions (#1668), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array_fill_keys extension (#1676), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array_reduce extension (#1677), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array pointer functions extension (#1678), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array_map extension (#1680), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in RegularExpressionPatternRule (#1679), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array_key_first and array_key_last extensions (#1681), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array_intersect_key extension (#1682), thanks @herndlm!
- Use TypeUtils::getOldConstantArrays in array_column extension (#1683), thanks @herndlm!