Repository navigation
Releases
Releases · vimeo/psalm
7.18.0 Contravariant templates
Features
@template-contravariant(also@psalm-and@phpstan-template-contravariant): a template for a class that only takes values, such as a handler, writer or mapper. ASink<Animal>fits where aSink<Dog>is expected, not the other way round, and Psalm reports the template where the class gives a value out.Plugins read the variance with/** @template-contravariant T */ interface Sink { /** @param T $value */ public function put(mixed $value): void; /** @return T */ public function last(): mixed; // InvalidTemplateParam } /** @param Sink<Dog> $sink */ function takesDogSink(Sink $sink): void {} /** @param Sink<Animal> $animals */ function f(Sink $animals): void { takesDogSink($animals); // no issue }
ClassLikeStorage::getTemplateVariance(). See Template contravariance; the templated annotations page was rewritten with checked examples. (#14669, @alies-dev)- Performance profile:
--debug-performance(short name--profile) prints where a run spent its time and memory: stages, workers, the slowest files, statements and functions, and plugin handlers. With a path it also writes a JSON profile that you can drop on https://psalm.dev/profile/ to see it as charts; the page reads it in your browser and sends it nowhere.See Finding out why Psalm is slow. (#14737, #14769, #14807, @alies-dev)vendor/bin/psalm --no-cache --profile=psalm-perf.json
- Agent skill for Psalm users:
skills/psalmteaches AI coding agents to run Psalm, fix its issues, write annotations and editpsalm.xmlthe way the docs recommend. Install it withnpx skills add vimeo/psalm --skill psalm, with thellm/skillsComposer plugin, or by copyingvendor/vimeo/psalm/skills/psalminto your agent's skills directory. (#13152, @roxblnfk; #14751, @danog; #14795, @roxblnfk)
Performance
Fixes
Templates and type variables
new Pipe(fn (int $x) => ...)with aClosure(T): voidconstructor param capsTatint, so a later$pipe->push('s')isIncompatibleTypeParametersinstead of reaching theintcallback. (#14669, @alies-dev)- A covariant template in the bound of a method template (
@template U of T) is reported in a param even after an earlier param usedUlegally. (#14669, @alies-dev) - Callbacks over a widened type variable (
new Coll([1]), then$c->add('x')) see every value it holds, not only the construction-site ones. (#14551, @shu-chen-dot-ca) nullno longer fits a template without a bound:fn() => nullforcallable(): T,[null]forlist<T>. (#14550, @shu-chen-dot-ca)- Trait method params use the types given to
@use. (#13429, @jirkace) @implements Wrapper<static>resolvesstaticto the object it is read from, and chained calls on such a value no longer hang. (#14572, @jirkace)@return static<NewK, NewV>on a template receiver keeps its new type arguments. (#14579, @jirkace)- An implementation with the same conditional return type as its interface method is not an
ImplementedReturnTypeMismatch. (#14502, @jirkace) - A conditional return type reads an argument that does not fit its param as it is (
preg_replace()on an array ofStringablereturns an array). (#14421, @jirkace) - A template array
Tread at akey-of<T>offset isvalue-of<T>. (#14586, @jirkace) is_int(),is_scalar()and similar checks narrow a template bounded byscalar,numeric,array-keyor an int range instead of reportingDocblockTypeContradiction. (#14545, @jirkace)- A literal class name can be identical to a template
class-string<T>. (#14365, @jirkace) - Iterating a star-projected collection (
Coll<*>) gives the template's bound instead ofmixed. (#14666, @alies-dev) - Generated stubs keep
@template, the variance and the declared order of templates instead of marking every template@template-covariant. (#14669, @alies-dev)
Narrowing and arrays
$a !== $bwith several possible values of$bdoesn't exclude them all from$a. (#14525, @jirkace)- After
isset($array[$k])with$kone of several literal keys,$array[$k]is the value of those keys. (#14646, @jirkace) $arr[$key]stays known to be set when$keyis narrowed insideif (isset($arr[$key])). (#13344, @jirkace)InvalidArrayOffsetis reported when an item is read again under an index narrowed to a key the array can't have. (#14767, @orklah)($a ?? null) !== nullassertsisset($a). (#14517, @jirkace)instanceofa parent class narrows to the parent class. (#14318, @jirkace)get_class()of a union of classes is the name of any of them. (#14366, @jirkace)- A property of an object intersected with an object shape (
V&object{x: string}) has the type of both. (#14546, @jirkace) - With
ensureArray*OffsetsExist, an offset that may be one of several literals is set only when each of them is. (#14606, @jirkace) - Appends stop growing a list shape at
maxShapedArraySize. (#14641, @jirkace) - Quoted keys of an array shape are read as PHP string literals (
"a\r\nb"). (#14600, @jirkace) - No crash on PHP 8.5 for an array key that reads as a huge number, such as the UUID
'6e5212ed-…'in Symfony'sFormconstraint. (#14797, @leonardsimonse) pow()of two int literals is an int literal. (#14505, @MikeFTV)
Control flow
- A variable unset before a
continueorbreakis possibly undefined after the loop. (#14509, @jirkace) - A property or offset narrowed before a loop forgets the narrowing after a
breakthat reassigned it. (#14456, @jirkace) - Variables assigned in the left operand of a negated
&&are defined in the next operands of the enclosing&&. (#14409, @jirkace) - A superglobal assigned on some paths only keeps its default type on the others. (#14406, @jirkace)
- A closure that falls through after a
throworexitin a branch returnsvoid, notnever. (#14793, @MikeFTV) - The return of a required file keeps the use of the outer
return, so it is noUnusedFunctionCall. (#14562, @jirkace)
Callables and nullsafe calls
- Arguments of a call after a
?->in a chain are analysed with a non-null receiver, as PHP skips the whole chain when it is null. (#14608, @jirkace) - The if-true assertions of a method called with
?->apply where the call is truthy. (#14531, @jirkace) - An enum case with
__invoke()is callable. (#14590, @jirkace) - A first-class callable of a method that an unsealed class forwards to
__call()is not anUndefinedMagicMethod. (#14411, @jirkace) staticin closure hints of calls in a trait on other objects resolves to that object. (#14446, @jirkace)- A
Closureobject of unknown signature is aClosure. (#14599, @jirkace) - No crash on a callable array whose object intersects a template. (#14594, @jirkace)
yield fromforwards the send type of the inner generator. (#14340, @jirkace)
Reported issues
- A value that shares only
nullorfalsewith the expected type isInvalidArgument, notPossiblyInvalidArgument, in closure params ofarray_map()and similar functions and in__set()calls on a@property. (#14742, @orklah) ParadoxicalConditionon a dead||operand next to other values of the same variable. (#14821, @orklah)- No
ParamNameMismatchfor a name another overridden method uses. (#14536, @jirkace) - No
MethodSignatureMismatchfor@no-named-argumentson parameterless methods. (#14799, @orklah) - A write through a
sethook is checked against the hook's param type. (#14538, @jirkace) - Properties that
array_column()reads are used. (#14560, @jirkace) - Before PHP 8.6, unsetting, passing by reference or referencing a property of a constant object is reported. (#14519, @jirkace)
@implementsnaming an interface the class doesn't implement gets the same message with or without type arguments. (#14650, @jirkace)@psalm-suppressbefore the expression ofechoor<?=is read. (#14527, @jirkace)
Stubs
ini_get()of a core setting no longer includesfalse. (#14809, @alies-dev)intval(),floatval()anddoubleval()report what the casts report. (#14311, #14805, @jirkace)ArrayObject::offsetSet()andArrayIterator::offsetSet()accept anulloffset. (#14516, @jirkace)pgsqlextension stub with thePGSQL_*constants, and the classes of thegeosextension. (#14637, #14631, @jirkace)FILTER_THROW_ON_FAILUREis defined and has no failure value. (#14359, @jirkace)Redis::auth()andRedisCluster::__construct()accept phpredis ACL credentials. (#14800, @orklah)- SPL classes,
WeakMap,SoapClient,MemcachedandPDOStatementuse the PHP 8 param names. (#14353, #14367, @jirkace) - The property map drops php-parser v4's
Name::$partsand uses v5'sArrayItemfor array and list items. (#14514, @jirkace)
CLI, config and tools
reportInfo="false"also dropsPossibly*issues that takeinfofrom their parent issue. (#14785, @alies-dev)- With an output format other than
console,phpstormandgithub, run statistics (--stats, the timing line, the--profilesummary) go to stderr. (#14745, @alies-dev) --update-baselinekeeps multi-line samples of CRLF files. (#14794, @ARAYN7011)- The config schema allows naming the class or property in the handlers of
MissingDependencyand four other issues. (#14649, @jirkace) --generate-stubskeeps the trait uses and the interfaces of a class with a parent. (#14564, @jirkace)- The class of
@psalm-scope-thisis scanned. (#14565, @jirkace) psalm-refactorrejects reserve...
7.17.0
What's Changed
Features
- Report the functions and classes of extensions composer.json doesn't declare by @danog in #14234
- Shepherd: Send baselined and info issue counts and analysis settings to shepherd by @alies-dev in #14673
- Shepherd: Write the Shepherd report to a file with --shepherd=file:// by @alies-dev in #14729
Fixes
- fix(class-string): get_parent_class() without an argument is bound to the parent class by @jirkace in #14316
- fix(property-map): ShellExec::$parts and MatchArm::$conds match php-parser v5 by @jirkace in #14341
- fix(assertion): count() compared to a constant narrows like a literal by @jirkace in #14323
- fix(cli): a missing root directory is shown as given when it is absolute by @jirkace in #14345
- fix(foreach): the iterated expression is analysed once for getIterator() by @jirkace in #14370
- fix(property): an offset write initializes an uninitialized array property by @jirkace in #14358
- fix(docblock): @psalm-import-type is read from any docblock before the class by @jirkace in #14328
- fix(unused-code): a method verified to return $this has no unused return value by @jirkace in #14337
- fix(combiner): a non-empty array and a Traversable are not combined into iterable by @jirkace in #14425
- fix(stubs): ArrayObject and ArrayIterator use the PHP 8 parameter names by @jirkace in #14324
- fix(arithmetic): int ** int may be a float when the exponent may be negative by @jirkace in #14317
- fix(stubs): strtolower and mb_strtolower of string literals are the lowercased literals by @jirkace in #14321
- fix(isset): keep the array value type when an ArrayAccess object is a union alternative by @jirkace in #13118
- fix(templates): new of the class itself binds its templates from the arguments by @jirkace in #13425
- fix(assertion): !== a bool literal of a template bounded by mixed is possible by @jirkace in #14362
- fix(enum): report a circular reference of an enum case value instead of crashing by @jirkace in #14350
- fix(switch): continue N targeting an outer switch leaves it like break N by @jirkace in #14368
- fix(comparison): loose comparison of numeric string literals compares their numbers by @jirkace in #14369
- fix(loop): a variable assigned in the right operand of || is defined after a while loop left through its condition by @jirkace in #14396
- fix(baseline): a character XML 1.0 forbids in the selected text keeps the baseline loadable by @jirkace in #14352
- fix(arrays): a nested write under a key a list doesn't have creates the offset by @jirkace in #14434
- fix(templates): a template of numeric can be identical to a string by @jirkace in #14430
- fix(override): #[\Override] on a property without a parent property is an InvalidOverride by @jirkace in #14390
- fix(algebra): a falsy variable holding a condition narrows to its negation by @jirkace in #14441
- fix(class_exists): the code after an if chain knows the classes of every block that reaches it by @jirkace in #14435
- fix(constant): use const imports win over the PHP constant of the same name by @jirkace in #14325
- fix(docblock): a param docblock of an implementation keeps the inherited return type by @jirkace in #14360
- fix(try): a variable assigned on some paths of a finally block keeps that type after the try by @jirkace in #14416
- fix(list): a write under the key array_key_last() returned for a list keeps it a list by @jirkace in #14428
- fix(templates): an int range bound to a constructor-only template stays open by @jirkace in #12944
- Fix --generate-stubs signatures for intersections, true/never/static/parent, enums and readonly by @shu-chen-dot-ca in #14114
- Fix assertions on $this of calls with no object, and make call-site InvalidDocblock suppressible by @orklah in #14678
- Expand the params of a final class's method with its static as the class itself by @shu-chen-dot-ca in #14203
- Write through an ArrayAccess item of an array with its offsetSet() by @danog in #14422
- Taint the items destructured from a mixed value or an ArrayAccess object by @danog in #14225
- Report the extensions the PHP 8.6 stub image doesn't build yet by @danog in #14683
- Check the extension of a symbol in every PHP version composer.json allows by @danog in #14685
- Give a foreach over an IteratorAggregate the taints of what getIterator() returns by @danog in #14687
- Keep the intersection of a template return type resolved to object by @danog in #14684
- Report the sinks of PDO and other extensions composer.json doesn't require by @danog in #14688
- Fix master CI by @danog in #14689
- fix(reconciliation): is_callable() leaves out a template whose bound can't be callable by @jirkace in #14622
- fix(report): by-issue-level shows (always) and (feature) for errors without a numeric level by @jirkace in #14632
- fix(arrays): a destructuring condition rules out the null a null value gives its variables by @jirkace in #14607
- refactor(methods): remove the unreachable CallMap fallback of compareMethodSignatureParams() by @jirkace in #14612
- fix(baseline): --update-baseline drops a duplicated code sample fixed once by @jirkace in #14561
- fix(stubs): Ds\Vector and Ds\Deque declare the mutating methods of Sequence by @jirkace in #14645
- fix(callables): match native callback functions case-insensitively by @jirkace in #14513
- fix(stubs): array_product() of booleans is 0|1 by @jirkace in #14634
- fix(reconciler): a string with a set offset is non-empty by @jirkace in #14638
- fix(types): too many non-empty literal strings combine into a non-empty string by @jirkace in #14640
- fix(traits): report an alias or precedence rule for a method the traits don't have by @jirkace in #14626
- fix(templates): a class-string-map is read and written with a literal Foo::class offset by @jirkace in #14616
- fix(stubs): preg_grep() can return false by @jirkace in #14574
- fix(reconciler): an object whose class is not a final class is not of it by @jirkace in #14548
- fix(new): report new of internal classes that can't be instantiated by @jirkace in #14570
- fix(assertions): a bare post-increment or decrement condition narrows the variable by @jirkace in #14534
- fix(loops): a variable the condition always writes holds what the breaks or the condition leave by @jirkace in #14541
- fix(foreach): a value variable bound by reference to the items of a property is limited to their type by @jirkace in #14583
- Follow taint through the builtin parameters PHP 8.0 renamed, when analysing for older versions by @danog in #14696
- fix(properties): keep analysing after an invalid static property assignment by @jirkace in #14515
- Fix: Shepherd reads local files for non-HTTP endpoints by @alies-dev in #14728
- Fix crash on a typeless @Property, @global or @param-out tag with its name on the next line by @orklah in #14704
- Fix Psalter ignoring autoloader and extraFiles when given a single path by @orklah in #14708
- Share the value-vs-expected-type issue tree between arguments, returns and properties (experimental) by @orklah in #14727
- Resolve static in the assertions of static calls by @orklah in #14721
- Report PossiblyInvalidPropertyFetch for @Property and __get() reads on unions with non-objects by @orklah in #14706
- Keep the extra key and value types of unsealed shapes in @method and --alter by @orklah in https://github.com/vi...
6.21.4
6.21.3
What's Changed
Fixes
- fix: class-string with template contains non-object type by @vincent4vx in #11755
Full Changelog: 6.21.2...6.21.3
7.16.0 Star projection
Features
- Star projection
Foo<*>: Kotlin's syntax for a generic argument you don't know. Reads go through the template's bound (Box<*>::get()isobjectforT of object), writes through it expectnever, andBox<*>accepts anyBox. See Star projection. (#13139, #13493, #14619, #14598, @alies-dev)
Performance
- Scan workers send back only the stubs they added: −9 % wall, −14 % memory on a large Laravel app (8 threads, no cache). (#12558, @alies-dev)
- Usage-inferred parameter types are recorded only for methods in the project directories: −8 to −15 % wall on apps that analyse their tests (one thread). (#13901, @alies-dev)
- No exponential clause growth in
||chains ofstr_starts_with(). Important for WordPress projects (#14653, @alies-dev) - Config loading skips directories a
**entry already matched: 60 to 85 % faster with**/vendor-style entries. (#14624, @alies-dev) - A class docblock is split into lines once for all its
@methodtags: scanning up to 5 % faster on classes with hundreds of them, such as AWS SDK clients and Laravel Facades. (#14620, @alies-dev)
Fixes
Templates
- An inherited property or callable resolves the parent's template through what the child passes to it (
@extends Base<list<U>>,@extends Base<Box<TModel>>, also across two@extendslevels). (#14487 @jirkace, #14558 @alies-dev) - Callables of a non-generic child of a generic class bind the parent's template. (#14578, @alies-dev)
newon a@template-covariantclass infersneverfor a template nothing can constrain, sonew Coll()fitsColl<int>. (#14449, @jirkace)
Callables and invokable objects
- An intersection whose later member has
__invokeis callable. (#14610, @alies-dev) array_map()with an invokable object as the callback infers the return type of__invokeinstead oflist<mixed>. (#14654, @alies-dev)- An invokable object, a function name or an array passed where a
Closureis expected is anArgumentTypeCoercion, not anInvalidArgument. (#14657, @alies-dev)
Other
--find-references-tofinds the calls of a function. (#14648, @jirkace)- A crashing worker says which file it was processing. (#14651, @jirkace)
- A failing worker pool task (e.g. a plugin hook throwing in a scan worker) is reported once, not again as an unhandled future. (#14595, @alies-dev)
Docs
Internal changes
- CI: Shared duplicated code and dropped dead code. (#14553, @orklah)
- CI: Perf bot: issues changed in place are shown as diffs, a regression warns at +10 % wall per project and +5 % in total, WordPress joins the corpus, and PRs that touch only tests or CI are skipped. (#14568, #14575, #14655, #14656, @alies-dev)
Full Changelog: 7.15.0...7.16.0
7.15.0
What's Changed
Features
- Give Closure::getCurrent() the signature of the closure it is called in by @danog in #14467
- Report native constants newer than the analysed PHP version by @danog in #14478
Fixes
- Date native symbols from a generated dictionary instead of loading every callmap by @danog in #14464
- Charge io for the pgsql, pcntl and posix functions that use the server, the process or the system by @danog in #14465
- Keep the callmap return type of a builtin whose stub declares none by @danog in #14466
- Let a lazy ghost initializer call the constructor of the object it is given by @danog in #14470
- Read C::{$name} like C::NAME when $name holds literal names by @danog in #14468
- Don't crash on a static call of a native method newer than the runtime by @danog in #14479
Internal changes
Full Changelog: 7.14.0...7.15.0
7.14.0
What's Changed
Features
- Full PHP 8.6 support: deprecations, API types and capabilities by @danog in #14413
- UX: List enabled plugins in the startup output by @alies-dev in #14510
Fixes
- Report an invalid psalm-refactor destination instead of crashing by @MohannadElemary in #14097
- fix: preserve array types after array_walk callbacks by @emreocell in #14173
- Keep what both operands of xor assign in an if condition by @shu-chen-dot-ca in #14357
- Resolve static nested in the hint of a typed closure param with the called class by @shu-chen-dot-ca in #14202
- fix(templates): localize the return type of a closure in a used trait by @jirkace in #12810
- fix(mixed): a non-empty mixed is never a falsy value, nor an empty mixed a truthy one by @jirkace in #12672
- fix(stubs): DOMNode::$ownerDocument is nullable by @jirkace in #14309
- fix(args): unpacking an array shape with integer keys that is not a list passes as many arguments as it has keys by @jirkace in #14415
- fix(reconciler): a loose comparison with a string keeps the scalars it can be equal to by @jirkace in #14429
- fix(stubs): DateTimeImmutable::getTimezone() may return false by @jirkace in #14343
- fix(stubs): pathinfo returns the array for PATHINFO_ALL by @jirkace in #14315
- fix(combiner): a class-string key of a merged keyed array stays a class-string by @jirkace in #14403
- fix(property): a static property of static type in a final class takes the class by @jirkace in #14351
- fix(property-map): remove the bogus WriteException entry of the manual property map by @jirkace in #14344
- fix(get_object_vars): resolve the class constants of a property type by @jirkace in #14342
- fix(arithmetic): % with a negative divisor takes the sign of the dividend by @jirkace in #14320
- fix(method-comparator): implemented return type messages name the method as written by @jirkace in #14314
- fix(call): call_user_func and call_user_func_array are matched case-insensitively by @jirkace in #14313
- fix(docblock): an intersection type in an @method parameter by @jirkace in #14338
- fix(context): a variable first assigned in a possibly skipped branch keeps its type by @jirkace in #14376
- fix(deprecated): a promoted property marked @deprecated is reported on use by @jirkace in #14310
- fix(loop): a foreach that is entered holds what an iteration ends with, at a continue too by @jirkace in #14418
- fix(filter_var): bools, empty literals and FILTER_FLAG_EMPTY_STRING_NULL of FILTER_SANITIZE_STRING by @jirkace in #14329
- fix(and): the left operand of && keeps the truthy clause of a nullable int by @jirkace in #14420
- fix(stubs): declare Closure::getCurrent() for PHP 8.5 by @jirkace in #14339
- fix(include): strict_types applies per file, not from the file that includes it by @jirkace in #14402
- Narrow ReflectionReference::fromArrayElement() for by-reference literal elements by @orklah in #14488
- Report GitHub Actions pull requests and other CI services to Shepherd by @alies-dev in #14472
- fix(visibility): a use adaptation changes the visibility a method call is checked with before __call() by @jirkace in #14399
- fix(isset): isset of an offset of a template array narrows the key to key-of by @jirkace in #14438
- fix(php85): writing a property of a constant object is a compile error before PHP 8.6 by @jirkace in #14405
- fix(mixin): an inaccessible property is read from the mixin through __get() by @jirkace in #14375
- fix(taint): a superglobal is still tainted after eval() by @jirkace in #14356
- fix(array-access): a null offset of an ArrayAccess object is checked by offsetGet by @jirkace in #14349
- Don't take matching another pattern for a paradox by @phcorp in #14444
- Report an override that widens or drops the native type of a class constant by @danog in #14485
Docs
- Document Shepherd on its own page by @alies-dev in #14473
Internal changes
- Fix the red filterVarSanitizeStringWithEmptyStringNull test on master by @alies-dev in #14493
- CI: Split BuildInfoCollector into one class per CI service by @alies-dev in #14498
New Contributors
- @emreocell made their first contribution in #14173
- @phcorp made their first contribution in #14444
Full Changelog: 7.13.2...7.14.0
7.13.2
What's Changed
Fixes
- Don't prefix PHP's Io namespace in the phar (crash on PHP 8.6 with threads) by @danog in #14414
- Don't crash combining type variables that all stand for never until bound by @danog in #14379
- Report only the ternary's own negated condition as redundant by @danog in #14417
- Keep the template arguments of the object in callable($this) and callable(static) params by @danog in #14423
Full Changelog: 7.13.1...7.13.2
6.21.2
What's Changed
Fixes
- [6.x] Fix: false
AmbiguousConstantInheritancefor a constant reached through a parent class and an interface by @Aerendir in #12663
New Contributors
Full Changelog: 6.21.1...6.21.2
7.13.1
What's Changed
Fixes
- Fix template arguments of a parent named in another case, share @extends/@implements/@use scanning by @orklah in #14397
- fix(assertion): a redundant negated assertion on a template keeps the template by @jirkace in #14330
- Share the template and result code of negated type assertions by @orklah in #14408
- Count a write through an ArrayAccess offset as a use of the object by @danog in #14410
Full Changelog: 7.13.0...7.13.1