Releases: phpstan/phpstan
Releases Β· phpstan/phpstan
2.1.55
This release fixes 55 issues! π
Bleeding edge πͺ
- Report invalid
DateIntervalconstructor arguments at analysis time (#5587), #14442, thanks @staabm and @VincentLanglet! - Report impure method overriding pure parent method in
MethodSignatureRule(#5584), #14563, thanks @VincentLanglet and @staabm! - Validate
define()andconstvalues against explicit types indynamicConstantNames(#5648), #14600, thanks @staabm and @VincentLanglet!
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 π§
- Don't report "no value type specified in iterable type array&callable" (#5565), thanks @staabm!
- Resolve method reflection for dynamic static calls (
$var::method()) to enable purity and side-effect checking (#5572), #14557, #5020, thanks @VincentLanglet and @staabm! - Track more expressions (#5596), #12517, #6486, #9155, thanks @VincentLanglet!
- Detect private promoted properties whose only reads are self-writes via
new self()(#5599), #14573 - Report wrong types being passed to
array&callabletype (#5573), #14549, thanks @VincentLanglet and @staabm! - Infer
numeric-stringforDateInterval::format('%a')when interval comes fromdiff()(#5674), #1452, thanks @VincentLanglet and @staabm!
Bugfixes π
- Recurse into parent expression in
IssetCheckandMutatingScope::issetCheckwhen property has propagated error (#5569), #14555 - Fix oversized-array self-rejection in
optimizeConstantArrays(phpstan/phpstan-src@9743346) - Update jetbrains/phpstorm-stubs (#5576), #14559, thanks @bitwise-operators!
- Track
$arr[$key]existence acrossarray_search/array_find_keyvia conditional expression holders (#5552), #14537, thanks @staabm and @VincentLanglet! - Do not narrow array to empty when
array_find_key()returns null (#5693), #14630 - Fix implode losing non-empty-string when ConstantArrayType has all-optional keys (#5578), #14558, thanks @VincentLanglet and @staabm!
- Narrow
DateInterval->daysafterDateTimeInterface->diff()(#5588), #14428, thanks @staabm! - Treat
*as assignment suppression insscanf/fscanfplaceholder counting (#5586), #10260, thanks @staabm and @VincentLanglet! - Do not prefix anything in resources/ when building phpstan.phar (phpstan/phpstan-src@5c28048)
- Walk ancestors for stub method PHPDoc on built-in classes without their own stub entries (#5695), #14632, thanks @staabm!
- Isolate alternation branches in
RegexGroupParser::walkGroupAst()to prevent non-empty/non-falsy state bleeding (#5602), #14575, thanks @staabm and @VincentLanglet! - Widen empty
ConstantArrayTypetoarraywhen resolving dynamic constant types (#5606), #8526, thanks @VincentLanglet and @staabm! - Fix counting
*scanf()format string placeholders (#5594), #14567, thanks @hakre! - Do not report
maybeinRandomIntParametersRulewhen either argument is an unboundedIntegerRangeType(#5622), #14468, thanks @staabm and @VincentLanglet! - Assign proper types for
$argcand$argvinglobalstatements (#5623), #12392, thanks @staabm and @VincentLanglet! - Do not propagate
isAlwaysTerminatingfrom immediately-invoked callable arguments to the outer call (#5604), #14582, thanks @VincentLanglet! - Resolve
ConditionalTypewhen subject-target relationship is deterministic despite containing template types (#5631), #11894, #8048, thanks @VincentLanglet and @staabm! - Return
nullfromArgumentsNormalizer::reorderArgs()when positional args after named args create holes beyond parameter count (#5637), #14596, thanks @staabm and @VincentLanglet! - Collect all remaining callable parameter types for variadic closure parameters instead of using only the matching index (#5634), #9240, thanks @VincentLanglet and @staabm!
- Switch HasMethodType/HasPropertyType from ObjectTypeTrait to MaybeObjectTypeTrait (#5605), #8217, thanks @VincentLanglet and @staabm!
- Augment
BooleanAndfalsey andBooleanOrtruthy type narrowing when left and right conditions narrow different expression keys (#5595), #14566, #13061, #7259, thanks @VincentLanglet! - callable-array intersection type is a constant array (#5647)
- Fix infinite recursion in specifyTypesForCountFuncCall with mixed TypeSpecifierContext (#5653), #14605
- Do not report
non-falsy-string == 0as always false inAccessoryNonFalsyStringType::looseCompare()(#5654), #14606, thanks @VincentLanglet and @staabm! - Prevent creation of IntersectionType with just HasOffsetValueType accessories (phpstan/phpstan-src@fa4e7d2), #14604
- Prevent issue with accessory-only IntersectionType (phpstan/phpstan-src@f2af15b)
- Re-check scalar types after integer range expansion in
TypeCombinator::union(#5660), #14610, thanks @staabm and @VincentLanglet! - Respect
@throws voidongetIterator()when determining foreach Traversable throw points (#5666), #6833, thanks @staabm and @VincentLanglet! - Check inner union types before delegating to
isSubTypeOfforLateResolvableTypeinUnionType::isSuperTypeOf()(#5645), #10942, thanks @staabm and @VincentLanglet! - Use pre-args scope for value types in array_push/array_unshift (#5579), #13510, thanks @predictor2718!
- Use before-scope for evaluating
array_spliceargument types (#5682), #13510, thanks @VincentLanglet and @staabm! - Fix: property.notFound in chained isset() with checkDynamicProperties (#5562), #13539, thanks @predictor2718!
- Invalidate property types after dynamic method calls (#5679), #3831, thanks @VincentLanglet and @staabm!
- Skip class name case check for type hints using explicit
use ... asaliases (#5671), #14617, thanks @VincentLanglet and @staabm! - Skip non-discriminating guards in
createConditionalExpressionseven when target is not tracked in the other scope (#5676), #14595, thanks @staabm and @VincentLanglet! - Preserve
TemplateTypeinIntersectionType::shuffleArray()when intersection is already a list (#5694), #14631 - Fix another shuffle() variant (#5696), thanks @staabm!
Performance ποΈ
- Lazily initialize AggregateSourceLocator to speedup bootstrapping (#5577), thanks @staabm!
- PhpFileCleaner: Use strcspn instead of regex for fast-skip in clean() (#5600), thanks @staabm!
- Cap cumulative unroll factor when nesting unrolled constant-array foreach (#5614), #14590
- DateFunctionReturnTypeHelper: prevent unnecessary
TypeCombinator::union()(#5629), thanks @staabm! - Memoize
ArrayType::isList()(#5680), thanks @staabm!
Function signature fixes π€
- Fix #14499: Mark Lua::__construct $lua_script_file parameter as optional (#5571), #14499, thanks @predictor2718!
- More concrete return type for
opcache_get_configuration([#5424](https:...
2.1.54
Improvements π§
- Improve DateInterval inference (#5486), #14479, thanks @VincentLanglet!
- Next autoindexes can be empty and setOffsetValueType with null offsetType returns ErrorType (phpstan/phpstan-src@5e793f7)
Bugfixes π
- Process unrolled foreach iteration body in original context to let nested loops stabilize (#5559), #9332, #14543
- Preserve conditional expressions in
invalidateExpressionwhenrequireMoreCharactersis true (#5560), #14545 - Recognize
[$obj, $method]as callable whenis_callable($obj, $method)is known true in scope (#5547), #4510, thanks @VincentLanglet and @staabm! - Replace instead of union when writing to optional keys via union offset in
ConstantArrayTypeBuilder(#5566), #14551 - Check
isFirstClassCallable()before callinggetArgs()on nestedFuncCallnodes (#5564), #14550, thanks @staabm and @VincentLanglet! - Preserve non-empty array guarantee in
ConstantArrayType::setOffsetValueTypewhen union key expansion produces all-optional keys (#5567), #14552, #14553
Performance ποΈ
- Cache methods in IntersectionType (phpstan/phpstan-src@c161e9f)
2.1.53
2.1.52
This release fixes 45 issues! π
Improvements π§
- Emit virtual
Assignnode forList_destructuring inforeachvalue position (#5504), #8075 - Narrow array key type after type-checking the key variable inside a
foreachloop (#5505), #7076 - Support for
static::SOME_CONSTin PHPDoc (#5510), #13828, thanks @VincentLanglet! - Allow GMP in increment/decrement operations (#5530), thanks @Firehed!
Bugfixes π
- Various array fixes (#5523), #7893, #2294, #14448, #11146, #11533, #13699, #13623, #13304, #12653, #3795, #14336, #11820, #13000, #13643, #13272, #13663, #10349, #8648
- Preserve constant array when assigning a union of scalars
- Preserve tracked nested ArrayDimFetch types through chained assignments
- More precise analysis for foreach iterating over constant array
- Resolve
ConditionalTypeForParameterchildren before converting toConditionalTypeto prevent infinite traversal (#5507), #13872 - Merge scope after
?->method call to account for argument short-circuiting (#5456), #10729, thanks @VincentLanglet and @staabm! - Track PHPDoc and modifier flags on
ExportedParameterNodefor result cache invalidation (#5518), #14520 - Autoloading should not be invoked for any string (#5519), #14514, #14511, thanks @staabm!
- More precise tracking
$valuein foreach (#5526) - Correctly mark all unpacked constant array items as optional in
array_merge/array_replace(#5525), #14526 - Fix: False positive: Conditional return type takes the wrong branch (#5362), #11565, thanks @VincentLanglet and @staabm!
- Fix: Allow readonly property init in child classes on PHP 8.4+ (#5513), #12871, thanks @predictor2718!
- Project narrowings through stored booleans for more expression kinds (#5528), #9455, #5207
- Track array_walk by-ref closure parameter modifications on array type (#5527), #14525
- Merge conditional-expression holders for the same target (#5529), #12677
- Project stored-boolean narrowings through
||truthy, Track destructure relationships across tagged-union foreach (#5531), #9519 - Fix: Template of imported type breaks imported type (#5360), #11314, #7152, #13332, thanks @VincentLanglet and @staabm!
- Track
$arr[$key]existence acrossarray_key_first/last+!== null(#5537) - Preserve TemplateArrayType across offset writes and traversal (#5553), #10749
- Two-stage collapse for oversized constant arrays (#5555), #8636
- Fix callable array intersection type offset narrowing (#5548), #3842, thanks @VincentLanglet and @staabm!
Performance ποΈ
- Cache class constant fetch type (phpstan/phpstan-src@a8704ac)
Function signature fixes π€
- Make bcround pure (#5499), thanks @still-dreaming-1!
- Make bcfloor, bcceil pure (#5509), thanks @staabm!
- Declare multiple apcu_ functions as impure (#5516), #14519, thanks @madmajestro!
- Declare Memcached methods as impure (#5536), #13444, #14534, thanks @VincentLanglet!
Internals π
- BenchCase - enable Bleeding Edge (phpstan/phpstan-src@99c018e)
- Revert fix (#5520), thanks @staabm!
- Fix PHPUnit warnings (#5522), thanks @staabm!
- Add non regression test (#5540), #2940, thanks @VincentLanglet!
- Add non regression test (#5545), #4352, thanks @VincentLanglet!
2.1.51
Improvements π§
Bugfixes π
- Fix ReflectionGetAttributesMethodReturnTypeExtension for UnionTypes (#5463), #14466, thanks @VincentLanglet and @staabm!
- Fix ErrorType leaking from array_key_exists with union key types in loops (#5487), #14489, thanks @VincentLanglet and @staabm!
- Fix infinite loop on recursive trait (#5488), thanks @samsonasik!
- Do not re-wrap
NeverTypeasTemplateMixedTypeinTemplateUnionType::filterTypes()(#5500), #14504 - Read class-constant
@vartype without triggering@extendsresolution (#5502), #14501
Internals π
- Improve
UnionType::accepts()(phpstan/phpstan-src@5cfa80a)
2.1.50
Bugfixes π
- Fix broken type narrowing with larger union types (phpstan/phpstan-src@77a3244), #14484
Function signature fixes π€
- Declare multiple mysqli_ functions as impure (#5481), #14473, thanks @VincentLanglet and @staabm!
2.1.49
Bugfixes π
- Use declared property type instead of scope-narrowed type when inferring generic
newexpression types (#5467), #11844, thanks @VincentLanglet and @staabm!
Performance ποΈ
- Use pairwise
TypeCombinator::intersectfolding for conditional expression holders to avoid exponential union distribution (#5482), #14475 - Fix more cases (#5482), #14475
- More pair-wise intersect (#5482), #14475
- Avoid 2^N
getAllArrays()expansion inimplode()return type extension (#5482), #14475 - Avoid 2^N
getAllArrays()expansion inConstantArrayType::getFiniteTypes()(#5482), #14475 - Bail early in
TypeUtils::flattenTypes()to avoid 2^NgetAllArrays()expansion (#5482), #14475 - Batch
unionWithinspecifyTypesForFlattenedBooleanOrfalsey path to avoid O(NΒ²) (phpstan/phpstan-src@7eab3d2) - Add flattening optimization for deep
BooleanAndchains in truthy context (phpstan/phpstan-src@3f5f2de) - Use hash map for O(1) key lookup in
ConstantArrayType(phpstan/phpstan-src@8019f65) - Fix infinite hang when analysing
src/wp-includes/user.phpin wordpress-develop (#5485)
Function signature fixes π€
Internals π
- Fix PHPUnit warning (#5484), thanks @VincentLanglet!
2.1.48
Improvements π§
- Report promoted properties with
readonlyor hooks as always unitialized (cannot be unset) (#5452), #14459
Bugfixes π
- Preserve list type in
ConstantArrayType::spliceArraywhen all keys are integers (#5480), #14472, thanks @VincentLanglet and @staabm! - Generalize
dynamicConstantNamesconstants to PHPDoc type if present (#5457), #9218, thanks @VincentLanglet and @staabm! - Use position-specific
getOffsetValueType()instead ofgetIterableValueType()when intersecting twoConstantArrayTypes (#5468), #11234, thanks @VincentLanglet and @staabm!
Performance ποΈ
- Fix for performance issue (phpstan/phpstan-src@6586de9), #14462
Internals π
- Add regression test for
@varannotation beforeforeachnot defining the expression variable (#5458), #6688, thanks @VincentLanglet and @staabm!
2.1.47
Major new features π
bisectcommand (#5431), #14443- Find the first PHPStan commit that introduced a regression
- This command performs a binary search over PHPStan releases, similar to
git bisect - Learn more Β»
Improvements π§
- Detect more AI agents (#5375), thanks @staabm!
- Add hint in VarTagTypeRuleHelper (#5400), thanks @VincentLanglet!
- Implement GMP operator type specifying extension (#5223), #14288, thanks @Firehed!
- Respect sys_temp_dir from the parent process (#5390), #14093, thanks @theodorejb!
- Update Symfony polyfills (phpstan/phpstan-src@9c3b62d)
Bugfixes π
- Fix: !in_array with enum values incorrectly narrows to NEVER (#5365), #14407, #13421, #8864, thanks @VincentLanglet and @staabm!
- Fix: PHPStan assumes string conversions cannot throw exceptions (#5391), #13806, thanks @VincentLanglet and @staabm!
- Fix ObjectType::equals (#5399), #3028, #14429, #5298, thanks @VincentLanglet!
- Fix: Two unbounded generics in conditional return are assumed to be always the same (#5336), #11430, thanks @VincentLanglet and @staabm!
- Fix: \settype() is not handled properly (#5404), #3250, thanks @VincentLanglet and @staabm!
- Fix: Call to function is_callable() with array{...} will always evaluate to true (#5409), #12063, #4608, thanks @VincentLanglet and @staabm!
- Fix: Allow throwing exceptions from __toString() not detected since level 4 (#5405), #5952, thanks @VincentLanglet and @staabm!
- Fix: Adding elements to empty array in
whileloop does not result in array being recognized as potentially non-empty forin_array(#5419), #13705, thanks @VincentLanglet and @staabm! - Fix: Ordering of Intersections matters for method calls, first matching wins (#5408), #11978, thanks @VincentLanglet and @staabm!
- Fix: Nullsafe operator chaining (#5407), #11073, thanks @VincentLanglet and @staabm!
- exit function is not internal, change isInternal method to return 'No' (#5420), thanks @spaze!
- Fix infinite recursion in ConstantArrayType::isCallable() via RecursionGuard (#5423), thanks @MizouziE!
- Fix infinite loop (#5426), #14439, #4957, thanks @staabm and @VincentLanglet!
- Preload polyfills in the PHAR (#5436), #14432
- Update BetterReflection to 6.70.0 (phpstan/phpstan-src#5429)
- Fixes: Readonly property modification through clone() is not reported outside allowed scope (#5432), #14063, thanks @VincentLanglet and @staabm!
- Support for covariant templates in interface properties in 8.4 (#5415), #12964, thanks @VincentLanglet and @staabm!
- Fix incorrect type-narrowing when using strict rules (#5435), #14446, thanks @VincentLanglet and @staabm!
- Do not report generic covariant issue without strict check (#5437), thanks @VincentLanglet!
- Fix: Conditional argument type not properly narrowing type (#5386), #10055, #13591, #12597, #10422, #6663, #4090, #11218, thanks @VincentLanglet and @staabm!
Performance ποΈ
- TypeCombinator::union optimization in case of many
*NEVER*(#5374), thanks @SanderMuller! - Do fast check first (#5396), thanks @VincentLanglet!
- List the most-often-analysed trait files in
-vvv(#5395), #14073, thanks @VincentLanglet and @staabm! - Fix performance degradation introduced in 2.1.41 (#5441), #14452, thanks @VincentLanglet!
Internals π
- TypeCombinator: Remove always true condition (#5383), thanks @staabm!
- Prevent duplicate argument re-normalizing (#5393), thanks @staabm!
- Add authors section in composer.json (#5389), thanks @VincentLanglet!
- Added regression test (#5425), #8835, thanks @staabm!
- Upgrade Dead Code Detector to 1.0.0 (#5430), thanks @janedbal!
- Add non regression test (#5442), thanks @VincentLanglet!
- Fix non regression test (#5444), thanks @VincentLanglet!
- Remove wrong specification (#5445), thanks @VincentLanglet!
- bisect: advertise gzip,deflate encoding when supported (#5434), thanks @staabm!
2.1.46
Improvements π§
- Properly union HasOffsetValueType in huge intersections describing the same offsets (phpstan/phpstan-src@429723d)
Bugfixes π
- Fix sealed class-string match exhaustiveness for ::class comparisons (#5305), #12241, thanks @mhert!
- Fix sealed class-string match exhaustiveness for generic sealed hierarchies (#5369), #14412
- Fix incorrect type narrowing with dependent types (#5373), #14411, #11328, #10085, #14211, thanks @VincentLanglet and @staabm!
- Fix false positive contravariant parameter with nested trait (#5244), #14320
- Properly preserve TemplateConstantArrayType (phpstan/phpstan-src@c71be49), #12355, #9828
Performance ποΈ
TypeCombinator::unionoptimizations (#5325), thanks @SanderMuller!