Mago 1.0.0-beta.12
This release is packed with major improvements to the static analyzer, focusing on enhanced type inference for
arrays, closures, and ArrayAccess
objects. We've also added support for recursive closures and array
unpacking on all iterables.
🚀 Features
- Array Unpacking on Iterables: The array spread operator (
...
) now works on alliterable
types, not just arrays. You can now unpack any object that implementsTraversable
, and Mago will correctly infer the key and value types. (#361) - Smarter
Psl\Regex
Analysis: A special type provider has been added forPsl\Regex\capture_groups
. Mago can now infer a precise shape for the returned type based on the capture group names you provide, giving you much better type safety when working with regular expressions. (#364)
🐛 Bug Fixes
- Recursive Closures: You can now write recursive closures without getting an
undefined-variable
error. The analyzer now correctly handles the pattern where a closure takes a reference to itself (e.g.,$fn = function () use (&$fn) { ... };
). (#368) - Closure Call Return Types: Invoking a closure assigned to a variable (e.g.,
$a = fn() => 'foo'; $b = $a();
) now correctly uses the specific inferred return type ('foo'
) instead of falling back to a genericmixed
. (#355) - Array Assignment on
null
: Assigning to an index on anull
or non-existent variable (e.g.,$a = null; $a[] = 1;
) now correctly promotes the variable to anarray
type, matching PHP's runtime behavior. (#360) - Shaped Array Inference: Fixed a critical bug where the analyzer would "forget" the shape of an array being built inside a loop, leading to false-positive errors. Type information is now correctly preserved. (#366)
ArrayAccess
Append: Appending to anArrayAccess
object with anon-negative-int
key type now correctly infers the new key asnon-negative-int
instead of a generalint
. (#362)- Enums with
self
&static
: Corrected an issue whereself
andstatic
were not being properly resolved to the enum's type within its own methods, eliminating false-positive errors. (#357) array_search
Stub: The built-in stub forarray_search
has been corrected to reflect that the$needle
is a value from the array, not a key. (#358)
🔧 Internal Changes
- Ecosystem CI Check: A new CI workflow has been added to automatically run Mago against popular downstream projects. This helps us catch potential backward-compatibility breaks before they are released.
Full Changelog: 1.0.0-beta.11...1.0.0-beta.12