github carthage-software/mago 1.62.0
Mago 1.62.0

one hour ago

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-out when 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 **, and strtolower(), strtoupper(), and their mb_ 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

  • @mixin traits: visits each mixin once for static calls, so traits that @mixin their 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-definitions is on. (#2836, 09bfea8)

Control Flow

  • catch blocks: see variables assigned before a throw in their try. (abf92e8)
  • finally blocks: one that assigns on some paths keeps the state after the try. (8df085e)
  • Catch-only assignments: a property assigned only in a catch keeps its declared type after the try. (#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 match over 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 break before an assignment leaves the variable possibly undefined. (43d7f3f)
  • Continues: assignments before a continue reach the end of a loop that may not run. (e2518b6)
  • foreach passes: skips the body for never items, and reassigns targets before every pass. (cb16b58, b74cfda)
  • By-reference foreach: a by-reference foreach over a property writes its items back. (f786c73)
  • for conditions: a short-circuited assignment in a leading for condition is possibly undefined. (62bc778)
  • for updates: a for loop's last update pass reports nothing. (937e378)
  • do-while: a condition on an unchanged variable no longer narrows it to never. (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 a Countable object's size can change. (#2799, 94cee05)
  • count($a ?? []): comparing it with a number narrows $a. (339d9da)
  • array_search() after in_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 and mixed: is false for non-numeric string offsets, and keeps ArrayAccess and strings. (2ef0749, 591a260)
  • Ignore-nullable arrays: isset() of their offsets keeps null. (8bb6b86)
  • Loose comparisons: compares two string literals, or a value with an empty array, the PHP 8 way. (c61b707, 1e60edb)
  • $this assertions: parent::, self:: and static:: calls apply them, and static stays 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'] ?? false keeps the key optional. (348a3c3)
  • Falsy mixed: type checks keep its falsy values. (4f265ca)
  • is_countable(): keeps countable callables and iterable arrays. (8a77dff)
  • method_exists() on mixed: keeps class names. (54749d5)
  • Destructuring conditions: a truthy one rules out a null source. (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

  • $_SERVER paths: 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(), and prev() keep the array's type. (7c1a1d6)
  • Spreading mixed: spreading mixed into 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_MIN is 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

  • never inputs: bind the templates they would fill to never. (#2767, dc3be50)
  • Inherited properties: resolve composed parent template arguments, and @property can 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, and new of an unbounded class-string template gives it. (8b842a7, 1cb809a)
  • Conditional returns: a non-null mixed is disjoint from null. (d105d3a)

Classes and Members

  • private(set) overrides: reports overrides of private(set) properties. (#2822, #2823, eb647ac)
  • Final interface constants: reports their overrides. (#2824, #2825, 275fdf8)
  • Override types: int no longer stands in for float in an override's native types. (a76870b)
  • Enum interfaces: only enums implement UnitEnum and BackedEnum. (f663223)
  • clone: always gives an object, and clone $this is static, 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: sends null when the inner generator has no send type. (2234d13)
  • Float closures: a closure declared to return float converts an int. (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 mixed template counts as mixed. (7b7cab8, 0d4b6df)
  • Class-strings of templates: keep only object bounds, and class-string<Closure> is valid. (d46a63b, 5a4a84c)
  • static in intersections: resolves to the receiver. (f0d8886)
  • static arguments: 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_DEBUG and PHP_ZTS: are bool since 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 false and null: array entries keep them when compared. (6bc8b0a)
  • Truthy mixed: no longer contains a value that may be falsy. (5350183)
  • @method defaults: a @method parameter defaulting to null is 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(), and clamp(). (#2800, #2801, d7eccc0)
  • PHP 8.6 deprecations: marks the symbols PHP 8.6 deprecates. (#2804, #2805, f7047a5)
  • Dom namespace: 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 and setAuthorizer(). (#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(): makes bits and channels optional, also in getimagesizefromstring(). (#2844, #2845, 676beeb)
  • xml_parse_into_struct(): corrects its return type and by-reference parameters. (#2848, #2849, 1ebfbc3)
  • array_product(): returns int for ints and 0|1 for 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, and PGSQL_LIBPQ_VERSION is non-empty. (693f733, 966b856)
  • ArrayObject and ArrayIterator: offsetSet() takes a null key. (2e99e2f)
  • Ds\Hashable: adds the interface. (4d2f2e6)
  • WeakMap: offset methods accept named arguments. (1778432)
  • MemcachedException: extends RuntimeException. (817148a)
  • PHP 8.5 constants: declares the runtime and socket constants. (102e1cd)
  • ini_get(): never returns false for 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

  • ambiguous-function-call: no longer reports a function the same file declares. (#2362, c64c3b5)

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(), or tryFrom(). (#2816, #2817, 684855c)
  • #[\NoDiscard]: reports it on void and never functions. (#2820, #2821, 47cba87)

Syntax

  • Alternative switch: accepts a newline after ?> before the first case. (#2806, #2826, 5575387)

CLI

  • --substitute: a substituted file uses the baseline of the file it replaces. (#2841, 3ad88fa)

🏗️ 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:

Issue Reporters

Thank you to everyone who reported issues that shaped this release:

Full Changelog: 1.61.0...1.62.0

Don't miss a new mago release

NewReleases is sending notifications on new releases.