Skip to content

Command Reference

The mago ast command is a powerful inspection tool that tokenizes and parses a single PHP file, giving you insight into its lexical and syntactical structure.

sh
Usage: mago ast [OPTIONS] <FILE>

Arguments

<FILE>

Required. The path to the single PHP file you want to inspect.


Options

--tokens

Display the stream of raw tokens generated by the lexer instead of the parsed AST. This is useful for debugging low-level syntax issues. This can be combined with --json for machine-readable output.

--json

Display the output (either the AST or the token stream) in a machine-readable, pretty-printed JSON format. This is ideal for integration with other tools and scripts.

--names

After parsing the AST, this flag runs the name resolver and prints a list of all symbols (classes, functions, etc.) and their fully qualified names. This is useful for debugging namespace and import resolution.

-h, --help

Print the help summary for the command.