Mago 1.62.0 lets extensions declare class initializers, applies @this-out, and reports constants that refer back to themselves or are inherited ambiguously. It fixes the @mixin trait hang and slow nested loops in generic code, and brings about 160 more fixes. Analyzer extensions move to MANA 2.3.
✨ Features
Analyzer
@this-out: applies@this-outwhen it narrows the receiver of a method call. (#2395, 4c5ec28)- Self-referencing constants: reports constants and enum cases whose value refers back to themselves. (e0b4c9a)
- Ambiguous constants: reports a constant a class inherits from two parents as
ambiguous-constant-inheritance. (c838ba1) - Literal results: types
pow()like**, andstrtolower(),strtoupper(), and theirmb_forms on literals. (5b8f8bb)
Extensions
- Class initializers: lets extensions declare class initializers by method or by attribute, such as
#[Before]. (#2837, 2d4aed9)
🐛 Bug Fixes
Analyzer
Performance
@mixintraits: visits each mixin once for static calls, so traits that@mixintheir class no longer hang. (#2831, #2812, da4f83b)- Generic loops: memoizes loops in code with templates or type aliases, which took exponential time when nested. (#2832, #2833, a26ebd5)
- Entry points: reads entry point attributes once, and only when
find-unused-definitionsis on. (#2836, 09bfea8)
Control Flow
catchblocks: see variables assigned before athrowin theirtry. (abf92e8)finallyblocks: one that assigns on some paths keeps the state after thetry. (8df085e)- Catch-only assignments: a property assigned only in a
catchkeeps its declared type after thetry. (#2719, 642a6db) - Throwing
??: writes on a right side of??that throws no longer leak. (2e273ee) ||and&&assignments: a variable assigned on the right of||or&&is possibly defined. (66a6878)- Large enums: a
matchover a very large enum is no longer called non-exhaustive. (f0da453)
Loops
- Truthy conditions: a loop with a truthy literal condition exits only by
break. (873ae7c) - Breaks: a
breakbefore an assignment leaves the variable possibly undefined. (43d7f3f) - Continues: assignments before a
continuereach the end of a loop that may not run. (e2518b6) foreachpasses: skips the body forneveritems, and reassigns targets before every pass. (cb16b58, b74cfda)- By-reference
foreach: a by-referenceforeachover a property writes its items back. (f786c73) forconditions: a short-circuited assignment in a leadingforcondition is possibly undefined. (62bc778)forupdates: aforloop's last update pass reports nothing. (937e378)do-while: a condition on an unchanged variable no longer narrows it tonever. (3333473)- Nested loops: a variable of an inner loop no longer forces another pass of the outer loop. (39f1b93)
Narrowing
count(): gives the known size of an array, and narrows sealed lists and shapes by size. (#2838, 99ba3de, e44687b, 92a98f7)count()of objects: no longer narrows, since aCountableobject's size can change. (#2799, 94cee05)count($a ?? []): comparing it with a number narrows$a. (339d9da)array_search()afterin_array(): finds the needle when both calls take the same arguments. (#2808, c99fec3)isset()offsets: narrows strings to non-empty, can fail on ints and bools, and reads only literal keys. (d2d49bc, 0ec7fa3, 0113543)isset()on strings andmixed: is false for non-numeric string offsets, and keepsArrayAccessand strings. (2ef0749, 591a260)- Ignore-nullable arrays:
isset()of their offsets keepsnull. (8bb6b86) - Loose comparisons: compares two string literals, or a value with an empty array, the PHP 8 way. (c61b707, 1e60edb)
$thisassertions:parent::,self::andstatic::calls apply them, andstaticstays late for open receivers. (08fc5b1, c8580ed)instanceof parent: a failed check keeps the variable's type. (84d4c3b)- Class-strings: a class-string identical to a literal class name is no longer
never. (8ccebc5) - Object narrowing: keeps what is known of an object's properties. (b61fc42)
- Lists: a list assertion narrows an int-keyed array to a list, and
array_is_list()may hold for[]. (6248c72, 30d029d) - Offset conditions: an offset condition that always holds drops the other branch. (dcf9833)
- Offset
?? false: the falsy branch of$a['k'] ?? falsekeeps the key optional. (348a3c3) - Falsy
mixed: type checks keep its falsy values. (4f265ca) is_countable(): keeps countable callables and iterable arrays. (8a77dff)method_exists()onmixed: keeps class names. (54749d5)- Destructuring conditions: a truthy one rules out a
nullsource. (0a2d7c1)
Nullsafe
- Nullsafe chains: later calls see a non-null receiver, and an offset in the chain keeps the short-circuit
null. (c8bb00a, 49c3752) - Nullsafe receivers: arguments see a non-null offset receiver, and
!empty()on a nullsafe access narrows its root. (995cde8, 478170b) - Nullsafe under
??: reads a possibly undefined receiver without a report. (74245e9)
Variables and References
$_SERVERpaths: may be empty in the CLI. (64c6473)- Reference destructuring: accepts a reference as a destructuring target. (aa4c528)
Arrays
- Strict index existence: accepts a union of keys the shape requires. (#2798, 79ed4d9)
- Array pointers:
end(),reset(),next(), andprev()keep the array's type. (7c1a1d6) - Spreading
mixed: spreadingmixedinto an array keeps unknown keys. (982c052) array_push(): pushing possibly empty unpacked values may add nothing. (0553acd)- Offset writes: drop the scalar members that throw, and a conditional write keeps the previous value. (f6114fc, dd25d80)
- Repeated keys: an array literal key that may repeat an earlier one overwrites it. (548a6ae)
Strings and Numbers
- Int overflow: int ranges no longer cap overflows, products keep their signs, and
-PHP_INT_MINis a float. (ee6b874, 8ac0e38) - Float literals: inexact int division,
pow()of floats, and ints above the int range give float literals. (980c552, 9180d45, 863c872) PHP_INT_MIN / -1: no longer crashes the analyzer. (0f4b50e)- Float casts: a
(float)cast of a string reads its exponent and leading spaces. (6d133c8) - String offsets: negative offsets of a literal string are valid. (6928939)
Generics
neverinputs: bind the templates they would fill tonever. (#2767, dc3be50)- Inherited properties: resolve composed parent template arguments, and
@propertycan narrow a templated one. (6b60abd, d2d62b6) - Template inference: a non-iterable argument part no longer stops it, and calls don't bind the caller's templates. (077c1f5, 139b2a2)
- Template casts and
new:(int)keeps an int template, andnewof an unbounded class-string template gives it. (8b842a7, 1cb809a) - Conditional returns: a non-null
mixedis disjoint fromnull. (d105d3a)
Classes and Members
private(set)overrides: reports overrides ofprivate(set)properties. (#2822, #2823, eb647ac)- Final interface constants: reports their overrides. (#2824, #2825, 275fdf8)
- Override types:
intno longer stands in forfloatin an override's native types. (a76870b) - Enum interfaces: only enums implement
UnitEnumandBackedEnum. (f663223) clone: always gives an object, andclone $thisisstatic, not$this. (fddfe35, 8358246)- Array properties: an array write initializes an uninitialized array property. (c3b06ef)
get_object_vars(): reads the properties it can see. (146404a)- Cached property reads: still evaluate a receiver that has side effects. (9d781b9)
Callables
yield from: sendsnullwhen the inner generator has no send type. (2234d13)- Float closures: a closure declared to return
floatconverts anint. (9608566) - Union receivers: a call on a union receiver evaluates its arguments once. (2835c82)
Diagnostics
- Only-false returns: ignored falsable returns no longer excuse a function that only returns
false. (68164e2)
Codex
- Generic parents: keeps an inherited docblock when generic parents agree after
@implements. (#2803, da181c3, 8ea3a75) - Nested callable templates: a generic first-class callable binds templates nested in its parameter types. (#2802, ee90224)
- Optional shape keys: a key the input cannot have no longer constrains the shape's values. (#2807, c638ae2)
- Intersection templates: resolves a template that is part of an intersection. (#2791, #2792, 593496b)
- Template bounds: may name later templates, and a bound of a
mixedtemplate counts asmixed. (7b7cab8, 0d4b6df) - Class-strings of templates: keep only object bounds, and
class-string<Closure>is valid. (d46a63b, 5a4a84c) staticin intersections: resolves to the receiver. (f0d8886)staticarguments: keeps the receiver's arguments for fewer templates, and method templates resolved to bounds. (5a6708a, d0b4ff6)- Object shapes: binds templates inside them, and a static property no longer satisfies one. (40f362c, 838c3f2)
- Callable objects: generic invokable objects bind class templates, and enums with
__invoke()are callable. (6cd1239, 8729012) - Array callables: an array callable of a class-string resolves the method. (43a88a1)
- Namespaced constants: shadow PHP's in class constant values, and fall back to global ones in initializers. (255b749, 6e4c380)
- Constant initializers: settle
??and ternaries they can decide, and keep every branch of the value. (59690b1, f3fe7e0) - Constant arithmetic: arithmetic on int constants gives an
int. (adf8fa9) PHP_DEBUGandPHP_ZTS: areboolsince PHP 8.4. (e388b77)- String literals: many merge into their shared string type, and ones without letters keep the other side's casing. (f063ec0, 5c4f187)
- Docblock strings: quoted shape keys and string literals decode escapes like PHP strings. (f6e0bac, ed3ce3a)
- Ignored
falseandnull: array entries keep them when compared. (6bc8b0a) - Truthy
mixed: no longer contains a value that may be falsy. (5350183) @methoddefaults: a@methodparameter defaulting tonullis nullable. (95c8409)- Inherited assertions: an override no longer inherits assertions inferred from the parent's body. (429a903)
- Cyclic hierarchies: no longer hang docblock inheritance. (90ca4f7)
- Scalar intersections: a native intersection with a scalar no longer crashes. (425e091)
- Required traits: a trait required by its user class is populated first. (496b4f9)
- Self-intersections: intersecting a type with itself no longer adds an intersection part. (4ed74fe)
Prelude
- PHP 8.6 signatures: corrects
isReadable(),isWritable(), andclamp(). (#2800, #2801, d7eccc0) - PHP 8.6 deprecations: marks the symbols PHP 8.6 deprecates. (#2804, #2805, f7047a5)
Domnamespace: marks its symbols as available since PHP 8.4 and 8.5. (#2839, #2840, cd12b3f)- DOM members: marks those added in PHP 8.1, 8.3, and 8.4 with their versions. (#2850, #2851, 81318be)
- Version gates: fixes ten symbols that PHP 8.0 and 8.1 already have. (#2842, #2843, 895b1af)
Pdo\Sqlite: adds the PHP 8.5 constants andsetAuthorizer(). (#2827, #2828, 94f73ca)SQLite3Stmt: marks the members PHP 8.5 added as available since 8.5. (#2829, #2830, 33a484e)ReflectionConstant: corrects its stub for PHP 8.4 to 8.6. (#2834, #2835, 7e3111b)Generator: marks it final. (#2818, #2819, 52035fa)getimagesize(): makesbitsandchannelsoptional, also ingetimagesizefromstring(). (#2844, #2845, 676beeb)xml_parse_into_struct(): corrects its return type and by-reference parameters. (#2848, #2849, 1ebfbc3)array_product(): returnsintfor ints and0|1for bools. (f078163)- Private constructors: classes PHP can't construct have private constructors. (78ee81e)
- URL encoding: encoding and decoding keep a string non-empty. (2f3d79c)
- Non-empty strings:
get_debug_type()returns a non-falsy string, andPGSQL_LIBPQ_VERSIONis non-empty. (693f733, 966b856) ArrayObjectandArrayIterator:offsetSet()takes anullkey. (2e99e2f)Ds\Hashable: adds the interface. (4d2f2e6)WeakMap: offset methods accept named arguments. (1778432)MemcachedException: extendsRuntimeException. (817148a)- PHP 8.5 constants: declares the runtime and socket constants. (102e1cd)
ini_get(): never returnsfalsefor a core setting. (f1cedf2)str_replace(): keeps the subject's keys and takes scalar items. (058c11f)- Reflection:
newLazyGhost()returns the reflected class, and attributes are objects. (654ad70)
Formatter
- Member access chains: formats idempotently with
preserve-breaking-member-access-chain. (#2783, #2811, 0c0b9f5) - Inline PHP templates: a tag after a broken tag line keeps its template alignment. (d51b676)
- Long binary chains: skips the comment walk when no comment is placed, ending cubic time. (#2846, #2847, 6fdf84b)
- Chains with comments: caches the comment check per expression, so files with comments are fast too. (#2852, #2853, 7c74f33)
Linter
Semantics
- Readonly defaults: allows readonly property defaults on PHP 8.6, and checks them in readonly classes. (#2787, #2788, 057ef25)
- Enum
__debugInfo(): allows it on PHP 8.6. (#2789, #2790, 7cdedf3) - Variadic promoted properties: reports them. (#2794, #2795, 3fdb7af)
- Abstract private methods: reports them outside traits. (#2796, #2797, 5d4afa2)
- Empty destructuring: reports empty lists in destructuring. (#2814, #2815, e5b6d40)
- Enum methods: reports enums that redeclare
cases(),from(), ortryFrom(). (#2816, #2817, 684855c) #[\NoDiscard]: reports it onvoidandneverfunctions. (#2820, #2821, 47cba87)
Syntax
CLI
🏗️ Internal
Codex
- Method maps: reserves method maps before inheriting from a parent. (0625df0)
Database
- Directory walk: follows symlinks in the parallel directory walk. (265954c)
🧩 Extension Protocol
Analyzer
- MANA 2.3: adds declarative class initializers, by method or by attribute, to plugin registration. (#2837, 2d4aed9)
Update the PHP SDK to 1.62.0 when upgrading Mago. Custom analyzer workers must use MANA 2.3; MANA 2.2 workers are not compatible. The linter protocol is unchanged.
🙏 Thank You
Contributors
Thank you to everyone who contributed to this release:
- @amateescu: #2792
- @karim-tao: #2845
- @lyn1dev: #2811
- @Neirda24: #2362
- @thunderer: #2788, #2790, #2795, #2797, #2801, #2805, #2815, #2817, #2819, #2821, #2823, #2825, #2828, #2830, #2833, #2835, #2840, #2843, #2847, #2849, #2851, #2853
- @zerone0x: #2826
- @barryvdh for the fix in #2812.
Issue Reporters
Thank you to everyone who reported issues that shaped this release:
- @4n86rakam1: #2806
- @amateescu: #2395, #2791, #2836, #2837, #2838
- @barryvdh: #2831
- @charliejc: #2808
- @devnix: #2767
- @dragosprotung: #2802, #2803
- @kamil-tekiela: #2719
- @karim-tao: #2844
- @maks-rafalko: #2841
- @nloyola: #2783
- @prismyq: #2798, #2799
- @simon-mundy: #2807
- @thunderer: #2787, #2789, #2794, #2796, #2800, #2804, #2814, #2816, #2818, #2820, #2822, #2824, #2827, #2829, #2832, #2834, #2839, #2842, #2846, #2848, #2850, #2852
Full Changelog: 1.61.0...1.62.0