Repository navigation
Mago 1.65.0 reads a @var docblock on a parameter as its type, adds the PHP 8.6 stream errors, polling and URI APIs, and fixes 74 bugs, most of them in the analyzer. It also analyzes long elseif chains and match expressions faster, and speeds up mago guard.
✨ Features
Codex
@varon parameters: reads a@vardocblock right before a parameter as the parameter's type. (#2779, #2963, e3c3cf3)
array_map(static fn (/** @var array{email: string} */ array $row): string => $row['email'], $rows);A @param tag on the function still wins.
Prelude
- PHP 8.6 stream errors: adds
StreamErrorMode,StreamException,stream_last_errors()and more. (#2966, #2967, 1fd0ed3) - PHP 8.6 polling: adds the polling API, such as
Io\Poll\ContextandStreamPollHandle. (#2968, #2969, dc48b98) - PHP 8.6 URI additions: adds
UriBuilder,UrlBuilder,getHostType(),url_percent_encode()and more. (#2970, #2971, b024f30)
🐛 Bug Fixes
Analyzer
Control Flow
switchfall-through: a case reached both directly and from the case above keeps what each path knows. (cf11e62)- Never-matching
caselabels: reports one at any place in a group of labels that share a body. (981520c) - Repeated
matcharms: reports an arm as unreachable when an earlier arm already matches its string. (a8e2a1a) tryandcatch: after acatchthat falls through, forgets what thetrybody proved before athrow. (425be40)- Long
&&and||chains: use less stack, so very long chains no longer overflow it. (78abdaa) yield from: accepts a generator whose send type isvoidin any generator. (e6595d0)
Loops
- Always-entered loops: variables that a
while (true)ordo-whilebody defines stay defined after an outertry. (b4eae4b) ++after an assignment:$i = 0; $i++;in a loop body makes$iexactly1, notint. (bbf0c74)
Narrowing
===on typed values: narrows both sides, so after$a === $bwithA $aandB $b,$bis anAtoo. (1103042)- Identical arrays: after
$x === $yon arrays of unrelated types, both may still be empty. (54d7544) - Loose
boolcomparisons:is_null($s) == false, or a comparison with afalseconstant such asFlag::OFF, narrows. (a075c8a) &&chains: forget a property narrowed before a call in the chain that may change it. (d220ab1)- Calls on union types:
$o->is($v)onA|Bnarrows$vonly by what holds whichever method runs, not byA::is()alone. (5cd2217) - Named arguments:
is_a(),is_subclass_of(),array_key_exists()and similar functions narrow with named arguments. (38f71fb) !=and numeric strings: after$a != '1',$ais no longer'01'or'1.0', which PHP treats as equal to'1'. (4714226)is_scalar()on callables: narrows acallableto acallable-string. (ea3564b)!is_scalar()on callables: removes thecallable-stringpart, so a lateris_string()is reported. (6cc2c47)is_object()on callables: narrows acallableto a callable object that keeps its signature and__invoke(). (fc1bfc9)is_resource()on templates: narrows a template with no bound toresource, notnull. (76d94ae)isset()with a computed key:isset($a[strtolower($s)])proves that$ais set. (02a2730)- Generic
staticassertions:@assert-if-true static<never> $thisnarrowsUser<null>toUser<never>. (#2960, 421a916)
Nullsafe
?->calls:$h?->foo($h = 1)leaves$has1ornull, not the original object. (966f816)?->with?? null:($box?->n ?? null) !== nullnarrows both$boxand$box->n. (ff1d9f3)
Variables and References
unset()on a reference: breaks the link, so later writes to the variable no longer reach the other one. (22c68d4)- By-reference captures: calling a closure that captures
$xby reference no longer turnsfalseintoboolin$x. (15c87d6) - By-reference variadics:
f($a, $b, $c)withint &...$itemsmay change every argument. (8e6a2ae) - Untyped by-reference parameters: may take any value, such as
$valueinfunction (&$value)passed toarray_walk(). (4dd50af) isset()and??: still report a possibly undefined variable used in them as a method receiver or a member name. (9b6df16)@varbeforeforeach: also types variables the loop does not bind, such as an outer$s. (ed981bc)@varon destructuring: types the variables of['a' => $a] = $rowand[$x, $y] = $pair. (aeb5c05)
Arrays
- Appends to lists with optional items:
$a[] = 3may land at any optional index, such as0when$amay be empty. (5c81d0b) - Offsets of
iterable:$items[0]on aniterable<int, int>readsintfrom its array part. (f9e39be) - Template keys:
$array[$key] = 3with$keyofT of 'a'sets keyaand keeps the array's shape. (324865d) array_map(null, ...): zips any mix of lists, shapes and unions of them into a list of tuples. (b5c2e89)array_multisort(): treats every array argument as reordered, with its integer keys renumbered. (cfe3941)
Strings and Numbers
abs(): returnsint|floatwhen the argument may bePHP_INT_MIN. (dfe9693)
Generics
- Inherited constructors: apply the
@extendsbinding, sonew IntBox('x')is reported whenIntBoxextendsBox<int>. (5a4d8a8) - Templates in intersections: infers
Tfrom any member of an intersection, such asBox<T>inMarker&Box<T>. (a425785) - Unpacked lists: infers templates from a list unpacked into a call, such as
identity(...[1]). (e14d687) - Unpacked arguments and closures: infer templates first, so
array_map(fn($v) => $v, ...$lists)knows$v. (e408f96) - Static calls on templates:
$obj::make()on aTreturnsTwhenmake()returnsstatic. (625f509) @template T of static: checks@extendsand@implementsarguments against the extending class. (4e4cbc7)- Conditional returns on
static:($x is static ? A : B)givesA|Bunless the receiver's class is final. (ded4de6) instanceofa generic subclass: allows$item instanceof Kidon aPar<'b'>whenKid<U>extendsPar<U>. (1d1213c)
Classes and Members
- Untyped constants over typed ones: reports
const D = 5that overridesconst int D, as PHP does. (aadd72a) @return selfoverstatic: reports it on a final method of a class that is not final. (b12018b)- Deprecated hooked properties: stops reporting a
@deprecatedproperty that its own hooks use. (3420805) (object)casts: a property of an object made by an(object)array cast takes any value. (d1aa550)stdClasspassed to calls: forgets its known properties after a call that may change them. (a091f4a)- Optional object shape properties: allows writing
$o->qonobject{q?: bool}, which may create it. (7398b16)
Callables
- Callable arrays:
[$obj, $name]()with$nameof'a'|'b'returns what either method returns. (441cf88) - Callable strings: reports
'f'passed ascallable(int=)whenf()requires its argument. (954f2ec) array_map()callbacks: reports a callback that needs more arguments than there are arrays. (8e0267d)- Unpacked lists in calls:
f(...['x', 1])checks each item against the parameter at its position, variadics included. (ae08c45) - Return type providers: no longer read arguments at or after an unpacked one, so
count(...[$list])is not misread. (0aeaca0)
Diagnostics
- Negative list indexes:
undefined-int-array-indexshows a negative index, such as-1, with its sign. (9d17b6d)
Codex
int<…>bounds: no longer wrap at or past the 64-bit limits;-$imay be afloatwhen$ican bePHP_INT_MIN. (8cfcca6)get_class()on enums: returns the enum'sclass-string, such asclass-string<Suit>. (37d1ff6)@param-outinheritance: a method without a docblock inherits@param-outfrom the method it overrides. (03fdb2c)- Shape rest types: reads
...<T>in an array shape as the type of the extra values, not of their keys. (7b895b3) - Inherited conditional returns: an override inherits a conditional
@returnwhen the parent has no native return type. (d426068) voidandnull: no longer reportsf() === nullwhenf()returnsvoid. (4f6d2d1)- Redeclared method templates: an override's own
@template Tapplies to the types it inherits, such asclass-string<T>. (a66ccf2) - Intersections with generics: reports
Box<D>&MarkerwhereBox<C>&Markeris expected. (718d885) - Projected templates:
Checker<*>andChecker<contravariant LeafNode>readTas its bound, such asNode. (85d01f7) static::in docblocks:static::REF_*resolves against the class of the call, such as a child's constants. (969b146)define(): defines the constant when called with named arguments in any order. (3524376)use constin docblocks: resolves imported and aliased constants, such asint-mask-of<FLAG_A|OTHER>. (db17bbb)
Prelude
RecursiveRegexIterator::MATCH: accepts it as the mode ofRecursiveRegexIterator, fixing a typo in the stub. (#2964, #2965, 4cc02a4)
Semantics
- Hooked properties: reports a promoted hooked
readonlyproperty, and virtual property defaults as PHP does. (#2956, #2957, b6e9421) - Interface properties: checks
private(set)andprotected(set)against the property's hooks, as PHP does. (#2954, #2955, 57bef3f) #[\Deprecated]on classes: accepts it next to#[\DelayedTargetValidation]on PHP 8.5 and later. (#2958, #2959, 154340c)
Syntax
yieldin conditions: ayieldin anif,elseif, loop header,switchcase orechomakes the function a generator. (08eb9b4)- String interpolation offsets: reports offsets PHP rejects, such as
"$user['name']", as parse errors. (#2972, #2973, 47816d7)
🏗️ Internal
Analyzer
- Long
elseifchains: indexes negated clauses, applies each negation once and shares clauses. (bb7e58b, 52181cc, 4779991, ab8c2d2) - Long
matchexpressions: indexes their negated clauses; arms share clauses and skip ones already applied. (4ad28c4, 884e6ff)
Algebra
- Clauses: caches and looks up negations by hash, and moves the left clause into its last disjunction. (61341db, 5c1d08f, fb90ebd)
Codex
- Enum case unions: combines them by sorting the cases. (3a36074)
Guard
- Builtin symbols: looks them up in tables built at compile time instead of decoding the prelude. (a301350)
- One walk: runs the perimeter and structural guards in a single walk over each file. (98426f0)
CI
- Pull request limit: enforces the open pull request limit on a schedule. (524b93e)
🧩 Extension Protocol
No protocol changes in this release.
🙏 Thank You
Contributors
Thank you to everyone who contributed to this release:
Issue Reporters
Thank you to everyone who reported issues that shaped this release:
Full Changelog: 1.64.0...1.65.0