Repository navigation
Fixes
Taint analysis
- No crash ("Undefined array key -1") when an array whose values a
foreachwrote back under their keys reaches a cast. (#14965, @orklah) - An unpacked element taints only the parameter it fills: in
f(...[safe(), $_GET['x']]),$firstis no longer tainted. (#14979, @shu-chen-dot-ca) - What
array_walk()andarray_walk_recursive()callbacks write to their by-reference param flows into the array. (#14963, @danog)
Templates and type variables
class-string<T>,key-of<T>,value-of<T>,T[K]andproperties-of<T>resolve whennewbinds the template:(new ReflectionClass(new stdClass()))->getName()isclass-string<stdClass>. An inheritedself<T&C>assertion narrows a subclass again. (#14981, @orklah)- No infinite recursion when an object is added to its own template, and
properties-of<T>over several classes includes the properties of each. (#14982, @orklah) - A
class-string<T>|Tparam given a class string bindsTto the class only, without a falseIncompatibleTypeParameters. (#14994, @orklah) - No hang when a class with
@template T of staticcalls a method returningTon$thisorstatic::. (#14978, @shu-chen-dot-ca)
Narrowing, loops and arrays
$x != ""and$x != 0removenulland the loosely equal bool from$x. (#14995, @orklah)- A variable that a nested
foreachover a non-empty list assigns before everybreakis defined after it. (#12439, @jarstelfox) - A variable read where it is undefined is no longer possibly undefined on the loop's next iteration, and with
extract()a variable assigned on one path is no longer read as possibly undefined. (#12442, @jarstelfox) - No false
PossiblyUndefinedVariableon$r?->m() ?? [], orTypeDoesNotContainNullon$r?->p ?? [], when$rmay be undefined. (#14998, @orklah) - A list written under keys it already has (its own
foreachkey,array_key_last()) keeps its shape. (#15009, @orklah) $a + [...]combined with a shape: no falsePossiblyUndefinedArrayOffseton keys both declare, and noInvalidArgumentwhen it is passed to a sealed shape param. (#15002, @orklah)- Offsets of
DOMNamedNodeMap,Dom\NamedNodeMap,Dom\NodeListandDom\HTMLCollectionare read by position or name instead of reportingInvalidArrayAccess. (#14535, @jirkace)
Properties and constructors
$object::$propis checked as a static fetch on the object's class, so undeclared and instance-only properties reportUndefinedPropertyFetch. (#12046, @HenkPoley)- No false
MissingConstructorfor a subclass inheriting the real constructor of a class a stub declares without one, and noPropertyNotSetInConstructorafterAncestor::__construct(). (#15001, @orklah) @psalm-suppress UndefinedConstantapplies to constants in docblock types (@var int-mask<NO_SUCH_CONSTANT>). (#13540, @alies-dev)
Purity
- The
DateTimeandDateTimeImmutableconstructors require only thetimecapability, and theDateIntervalconstructor is pure. (#14962, @jirkace)
Stubs
- Global constants added in PHP 8.5 (
CURLFOLLOW_ALL,ETH_P_ALL,PHP_BUILD_DATE, …) are declared. (#13019, @alies-dev) DateInterval::createFromDateString()no longer returnsfalseon PHP 8.3+. (#11849, @xelaris)SQLite3Result::columnName()can returnfalse. (#11819, @stof)ReflectionObjectis generic, likeReflectionClass. (#11774, @Kenny1911)- The property map covers ext-mongodb 2.3. (#11838, @alcaeus)
Language server and --alter
- The language server keeps the types and references of a file without class methods when it analyses another file, so hover and go-to-definition keep working there. (#15003, @danog)
--alterwrites only native types the analysed PHP version supports (noobjectbelow 7.2) and writesint|stringforarray-keyfrom PHP 8.0. (#14933, @orklah)
Internal changes
New Contributors
- @Kenny1911 made their first contribution in #11774
- @xelaris made their first contribution in #11849
Full Changelog: 7.21.0...7.21.1