This is a landmark release! 🎉 We are thrilled to introduce comprehensive support for by-reference analysis, a major step forward in Mago's ability to understand complex PHP code. Alongside this huge new feature, this release continues our focus on polishing the formatter and improving the accuracy of the type system.
✨ Major Feature: By-Reference Analysis
Mago now understands by-reference semantics! This is a foundational feature that replaces previous "unsupported operation" warnings with deep, accurate static analysis.
- Core Operations Support: The analyzer now correctly processes all major by-reference operations, including assignment (
$a = &$b
), passing arguments to by-reference parameters, returning by-reference,foreach
loops (foreach ($arr as &$value)
), anduse (&$var)
in closures. - Context-Aware Constraint Validation: Mago reports detailed, helpful errors for reference constraint violations. The error messages are tailored to the source of the constraint, explaining why a variable's type is restricted (e.g., because it's a
global
,static
, a by-refparameter
, or was passed as anargument
to a method). - Robust Branch Reconciliation: The logic for merging variable states from
if
/else
branches has been completely rewritten to accurately handle by-reference variables in conditional scopes.
💅 Formatter Fixes
We've continued to refine the formatter for more stable and predictable output.
- Idempotent Comment Handling: Fixed several bugs where comments could be lost or mangled during formatting, especially around the closing parenthesis
)
of function calls and betweenif/else
blocks separated by blank lines. The formatter is now more robust and idempotent. - Whitespace Consistency: The formatter now correctly handles tab characters (
\t
) as insignificant whitespace, preventing them from causing incorrect layout decisions around trailing comments.
⚙️ Other Fixes & Improvements
- Analyzer & Codex:
- Smarter Docblocks: The scanner now intelligently prioritizes tool-specific tags, preferring
@psalm-*
then@phpstan-*
over generic@var
and@return
tags to ensure the most specific type is always used. - Dogfooding: We're now running
mago analyze
on our own Composer plugin in CI! This has already helped us find and fix a bug in template type inference related to empty arrays.
- Smarter Docblocks: The scanner now intelligently prioritizes tool-specific tags, preferring
- Stubs:
- Added more stubs for the
imagick
extension, improving analysis for projects that use it. Thanks, @Bleksak!
- Added more stubs for the
Closed Issues
This release closes the following issues:
Full Changelog: 1.0.0-alpha.9...1.0.0-alpha.10