Mago 1.64.0 lets a class declare what a yield of its instances returns, and fixes 21 bugs, most of them in the analyzer and the PHP stubs.
✨ Features
Analyzer
- Typed yields:
@mago-yield Ton a class makesyield $loadreturnT, such asUserfor aLoad<User>. (#2944, cbd34e0)
A class inherits the tag from its parents and interfaces. When any part of the yielded value lacks the tag, yield keeps the generator's send type.
🐛 Bug Fixes
Analyzer
Arrays
isset()andif: keeps an array key thatisset()proved to exist after anifthat does not change it. (#2953, fd82833)- Class constant keys: treats
$row[self::KEY]and$row['key']as the same key when the constant holds'key'. (fd5cf55) empty()on array keys: no longer addsnullto an array key that holds a non-null value after anempty()check on it. (d3a653d)- String-key writes:
$data['a'][$key] = 1with a string$keymakes$data['a']a keyed array, not a list. (016e74e) - Missing shape keys:
isset()on a key a closed array shape lacks no longer types the key like the shape's other values. (2b0a5d8)
Narrowing
=== []: narrows a value compared with[]to the empty array, not toCountable. (#2880, #2936, f3039d3)- Assignments in branches: drops what an outer condition said about a variable that an
ifbranch assigns. (#2881, #2939, 7f8d79d) $thisin traits: narrows$thisin a trait after aninstanceofcheck, such asassert($this instanceof Base). (#2935, 6bea50f)- Nested property reads: reports a possibly null object in
$a->b->cread again after anisset()orempty()check. (#2940, eabab17)
Classes and Closures
- Dynamic properties: stops reporting
non-existent-propertyfor classes marked#[AllowDynamicProperties]. (#2911, 2b4c6e4) - Unknown parent classes: allows calls and property reads on
A&BwhenBextends a class Mago cannot find. (4d82dae) - Typed closure parameters: a closure parameter typed
BoxgetsBox<Product>from the expected callable. (#2952, 34042ec)
Codex
- Inherited assertions: resolves templates in identity (
=T) and equality assertions a class inherits from a generic parent. (95d0d6e)
Prelude
- Constant values: gives eleven constants, six of them on
Pdo\Sqlite, the values PHP uses. (#2926, #2927, 183b9a3) RegexIterator: adds seven missing methods, such asgetMode()andsetFlags(). (#2928, #2929, da94240)- Nonexistent symbols: removes 35 symbols that no PHP version defines, such as
S_ALLandPDO::__sleep(). (#2930, #2931, c0d5980) __debugInfo(): adds the method toArrayObject,ArrayIterator,SimpleXMLElementandGenerator. (#2950, #2951, 751fab9)- PHP 8.6 curl constants: adds five constants, such as
CURLOPT_SEEKFUNCTION. (#2946, #2947, 0f12b1e) - PHP versions: corrects the versions of four symbols, such as
SensitiveParameterandopcache_jit_blacklist(). (#2948, #2949, 1a1ca9d)
Semantics
finalproperty hooks: reports afinalproperty hook that is also abstract or private. (#2932, #2933, 78f35b7)- Virtual properties: reports a virtual property with
private(set)orprotected(set)and only one hook. (#2942, #2943, 779c120)
🧩 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:
- @bendavies: #2880, #2881
- @FluffyDiscord: #2952
- @kamil-tekiela: #2940
- @pfrenssen: #2935
- @prismyq: #2953
- @ruudk: #2944
- @smuuf: #2911
- @thunderer: #2926, #2928, #2930, #2932, #2942, #2946, #2948, #2950
Full Changelog: 1.63.2...1.64.0