Features
Conditional Return Types
Psalm now supports conditional return types.
Improved --diff mode
Psalm's --diff
mode should now produce all the same issues that running without --diff
does (#3024, #3032)
Additionally, it should now run much faster for small changesets.
With this change, --diff-methods
is now implied when running --diff
.
Improve detection of problematic array types
Previously when dealing with arrays the mixed
type subsumed everything in its path. Since Psalm converts any bare PHP array
types to array<array-key, mixed>
, that mixed
type can hide real bugs, such as in the following code: https://psalm.dev/r/a97351e870 (this corresponds to code that caused an outage on vimeo.com).
This version of Psalm introduces slightly more careful array handling, and allows unions on mixed
inside arrays in certain circumstances to allow you to catch more of these sorts of errors.
Other features
@psalm-property-read
and@psalm-property-write
are now supported as prefixed versions of@property-read
and@property-write
- thanks @iggyvolz (#3013)- Psalter can now be run without using cache (via
--no-cache
) - thanks @orklah! - You can now use a
@psalm-trace
annotation to figure out what type Psalm infers for a given variable – thanks @m0003r (#3080, #3106) - Docblock inheritance for function params is now just position-dependent, not name dependent as previously (#2722)
Bugfixes
- improve handling of templated assertions when calling
array_filter
(#3008) - fix templating of properties (#3027, #3035)
@return static
is now enforced in places it should have been, but was not- variables set in conditional branches of
while
expressions are now more completely understood (#3034) - Psalter don’t suggest hard return types for functions that don’t always return (#3030)
- Allow
__invoke
to be called on unions with non-objects (#3033) - Allow inheritance from classes that only exist in stubs (#2191)
- Fix class constant access rules for constant defined in subclass (#3014)
- Use a better method for determining switch case complexity, preventing crashes (#2728)
- @LeSuisse updated the return value of
zip_open
- Improve handling of generators (#3058, #3057)
- Prevent
array_key_exists
calls from changing the array type (#3061) - Allow comparing
self
-returning trait methods in 7.4 without a MethodSignatureMismatch (#3042) - Perform more intelligent templating for callable arrays passed to
array_map
(#3039) - Improve handling of intersection types when merging templated types (#3082)
- Psalm now infers template upper and lower bounds correctly, and will present more useful error messages when they don’t match (#3084)
- Improve handling of elseif clauses (#3091)
- Forget what's been asserted in methods when checking constructor initialisation (#3096)
- @Ocramius improved the return type for ReflectionProperty::getType() (#3093)
- @lhchavez added the ability to annotate intersections of arrays in docblocks (#3064)
- @mpesari updated property types for
mysqli
objects (#3114) - Prevent a crash when encountering a
@method
annotation with a dash in the method name (#3107) - Perform intersections on arrays after assertions on their key types (#3095)
round
always returns afloat
(#3092)- Allow
instanceof
checks with templated class-strings (#3116) - All caches are now invalidated when the composer lockfile changes (#3117)
- Some method getters are now automatically memoised - thanks @m0003r (#3122)