Mago 1.0.0-beta.9
This release focuses on deep type inference for ::class
comparisons. It also includes a new linter rule to help modernize your code, along with several important bug fixes and community contributions.
✨ Features
🧠 Smarter ::class
Analysis
The analyzer is now significantly smarter about the ::class
magic constant, enabling more powerful and precise type narrowing.
::class
asinstanceof
: A condition likeif ($var::class === A::class)
is now treated as aninstanceof
check, correctly narrowing the type of$var
toA
within the block. This works across all control structures, includingif
,switch
, andmatch
, and correctly handlesfinal
vs. non-final
classes. (Closes #367)- Improved
class-string
Logic: This is powered by a completely overhauled understanding ofclass-string
types. The analyzer can now reconcile literal class strings from unions and resolves$foo::class
onfinal
objects to a precise literal type. - Clearer Type Display: To make this distinction obvious, literal class strings are now displayed as
class-string('Foo')
, while generic class strings remainclass-string<Foo>
, making error messages much easier to understand.
🕵️ New Linter Rule: prefer-arrow-function
A new linter rule, prefer-arrow-function
, has been added to the Best Practices category. It identifies traditional closures that can be simplified to the more concise arrow function syntax and provides a potentially unsafe autofix.
🐛 Bug Fixes
- Analyzer: Fixed incorrect type inference for iterators, especially when only a value type is provided (e.g.,
Iterator<Value>
). A new, more precise return type handler for the SPL functioniterator_to_array
has also been added. (Closes #359) - Analyzer: Fixed an issue where the type of a class constant that references another constant (e.g.,
const A = B::C
) was not being fully resolved, leading to more accurate type inference. (Closes #363) - Analyzer: Corrected a bug where variables in a
foreach
by-reference loop (... as &$var
) were sometimes reported as undefined. A new warning (reference-reused-from-confusing-scope
) has also been added to detect a common source of bugs with lingering references after a loop. (Closes #369) - Docblock Parser: The parsing of
@param
tags is now more robust, correctly normalizing the variable name and handling trailing punctuation, by-reference (&
), and variadic (...
) syntax. Thanks to @z4nder! (Closes #376)
📝 Documentation & Community
- The documentation for Helix users has been updated to use the project's
mago.toml
by default. Thanks to @Bleksak! (Closes #349) - For contributors, a Nix flake has been added to provide a reproducible development environment. Thanks to @z4nder! (Closes #372)
- A sitemap has been generated for the documentation website to improve discoverability.
🤝 New Contributors
Full Changelog: 1.0.0-beta.8...1.0.0-beta.9