Compiler reference: phemc commands, options and output
phemc is the Rust compiler that turns .phem files into PHP and Twig. This page lists the phemc commands (build, check, watch, lsp) with their options and defaults, the files the build writes, the diagnostic codes, static analysis of the compiled code, and the related Symfony console commands. To install Phem, see Install and configure Phem. For the production build, see Deploy a Phem app.
Build pipeline#
A Phem application is a Symfony application with PhemBundle, and it needs two build steps before it can serve a page:
phemc buildcompiles the.phemfiles to PHP and Twig, invar/phem/.bin/console phem:warmupcompiles the generated Twig templates into the Twig cache.
phemc build runs step 2 for you. At runtime, nothing parses a .phem or a .twig source.
phemc commands#
Each command runs from the project root, the directory that contains bin/console. Paths in arguments and options are relative to it:
| Command | Purpose |
|---|---|
phemc build <src> |
Compiles the sources, writes the output directory and warms up the Twig cache |
phemc check <src> |
Reports the diagnostics and writes nothing. phemc check <file> and phemc check - check one file |
phemc watch <src> |
Builds, then rebuilds on each change, and restarts an optional command |
phemc lsp |
Runs the language server on stdin and stdout |
phemc mcp |
Runs the Model Context Protocol (MCP) server on stdin and stdout, for coding agents |
phemc docs [<key>] |
Shows the docs of this version of Phem, or the guide of a package |
phemc components [<name>] |
Shows the components of the application and of the packages, or one component |
phemc examples [<name>] |
Shows the examples of the packages, or the code of one example |
phemc search <query> |
Searches the docs, the components and the examples |
phemc --help lists the commands, phemc <command> --help lists the options of one command, and phemc --version prints the version.
phemc build#
phemc build compiles the .phem files of the source directory and of the Composer packages, writes the output directory, and then runs the Twig warmup:
phemc build srcIt prints a summary on stderr:
phemc: compiled 15 file(s), 24 template(s), 10 page(s); 43 file(s) changed, 0 warning(s) in 51 ms
phem: compiled 24 template(s) into the Twig cache in 250 msThe <src> argument is the source root of the application, for example src. The command takes these options:
| Option | Default | Effect |
|---|---|---|
--out <dir> |
var/phem |
The output directory. Set the phem.build_dir option to the same path |
--php <bin> |
php |
The PHP binary that runs the Twig warmup |
--no-warmup |
off | Skips bin/console phem:warmup after the build |
--examples-of <package> |
none | Compiles the examples of a package too (see Help coding agents use the components). Give it again for more packages |
The build has these properties:
- Incremental output: it writes a file only when its content changed, so the Twig cache and OPcache stay valid. It deletes the output of a removed source file or a removed package
- All or nothing: when a file has an error, it prints the diagnostics and
phemc: build failed: 1 error(s), 0 warning(s), writes nothing, and exits with code 1 - Composer packages: it also compiles the
.phemfiles of each installed package that setsextra.phem.sourcein itscomposer.json(see Component packages). The summary then counts them:compiled 42 file(s) (2 package(s)), … - Warmup environment: the warmup runs in the environment of
APP_ENV. When the project has nobin/consoleor novendor/autoload.php, the build skips the warmup and says so. A failed warmup exits with code 1
In debug mode (APP_ENV=dev), Symfony rebuilds the container and the routes when the manifest or a compiled page changes, so a new component, page or route doesn’t need cache:clear.
Build output directory#
The build writes the compiled application to var/phem/ (or the --out directory):
var/phem/
├── php/Ui/HomePage.php the PHP code of HomePage.phem
├── php/vendor/acme/ui/… the PHP code of a Composer package
├── templates/Ui/HomePage.0.twig one Twig template for each markup literal
├── templates/vendor/acme/ui/… the templates of a Composer package
├── manifest.php, manifest.json components, pages and template line map
└── autoload.php requires all the compiled PHP files
var/cache/<env>/twig/ the Twig cache, filled by the warmupEach markup literal becomes new \Phem\Element('Ui/HomePage.0.twig', [...]) in the PHP code, and its template has the Twig name @phemc/Ui/HomePage.0.twig. The manifest lists each component (its kind, source, props, slots and replaces target), each page, and the .phem file and line of each template.
var/phem/ isn’t a cache. It holds the compiled code of the application, it’s the same for all environments, and only phemc build writes it. cache:clear and rm -rf var/cache leave it in place. Don’t commit it.
The compiled PHP keeps the line numbers of the .phem file, and its first line names the source (<?php /* compiled by phemc from src/Ui/Report/Tally.phem; do not edit */). Because the manifest maps each template back to its .phem file and line, the Symfony error page and the console show src/<file>.phem (or vendor/<package>/… for a package) for an error in markup.
phemc check#
phemc check reports all the diagnostics of the application and its packages, writes nothing, and exits with code 1 when there is at least one error. Use it in continuous integration (CI):
phemc check src| Option | Default | Effect |
|---|---|---|
--format <format> |
text |
text prints the diagnostics on stderr; json prints them on stdout, for editors and other tools |
--src <dir> |
src |
The source root of the application, when the argument is a file or - |
--stdin-path <file> |
none | With -: the text on stdin replaces this file. Without it, the text is a new file of the application |
--examples-of <package> |
none | Checks the examples of a package too |
Give a .phem file in place of the source root to check only this file. The command compiles the whole project, so the imports and the components of the other files resolve, but it shows only the diagnostics of this file. Give - to check a text on stdin, for example a file that an agent writes before it saves it:
phemc check src/Ui/HomePage.phem
cat draft.phem | phemc check - --stdin-path src/Ui/HomePage.phemThe summary then names the file: phemc: checked src/Ui/HomePage.phem: 0 error(s), 0 warning(s). A file that isn’t in a source root is a new file of the application.
In the text format, each diagnostic shows its code, the .phem line and column, a label and a hint, and the command ends with phemc: checked 15 file(s): 1 error(s), 0 warning(s):
E011
× `<Profile>` has no prop `persn`
╭─[src/Ui/Scientist/ScientistPage.phem:16:22]
15 │ <div>
16 │ <Profile persn={{ user }} />
· ─────
17 │ </div>
╰────
help: its props are: personThe json format keeps the same exit code:
phemc check src --format json{"files": [{"file": "src/Ui/Scientist/ScientistCard.phem", "diagnostics": [{"severity": "error",
"code": "E010", "message": "unknown component `<Avatr>` (resolved to `App\\Ui\\Scientist\\Avatr`)",
"label": null, "help": "declare `#[Component] function Avatr()` in a .phem file, or check the `use` imports",
"start": {"line": 30, "character": 13}, "end": {"line": 30, "character": 18}}]}]}The JSON fields follow the Language Server Protocol (LSP) conventions:
file: the path from the project root. A file with no diagnostic isn’t in the listseverity:errororwarninglabel,help: the label of the span and the hint, ornullstart,end:linestarts at 0, andcharactercounts UTF-16 code units
Both formats leave out the warnings of a Composer package, because the application can’t fix them. The errors of a package stay in the list. Both formats also leave out the hints (see Diagnostic codes).
phemc watch#
phemc watch runs a build, then rebuilds each time a .phem file changes. With --exec, it also starts a command after each successful build and restarts it after the next one:
phemc watch src --exec "frankenphp run --config Caddyfile"It takes the options of phemc build (--out, --php, --no-warmup, --examples-of) and one more:
| Option | Default | Effect |
|---|---|---|
--exec <cmd> |
none | The command to start after a successful build, and to restart after each later successful build. It runs with sh -c |
The watcher behaves as follows:
- Watched files: the
.phemfiles of the source root, of each package root and of the examples of--examples-of, andvendor/composer/installed.json. A change ofinstalled.json(composer require,composer update) reads the package roots again and rebuilds - Debounce: after a change, it waits until no change arrives for 150 ms, then builds once
- Failed build: it prints the diagnostics and
phemc: the previous build keeps running. It doesn’t restart the command, so the previous server keeps serving the last good build. When the first build fails, the command doesn’t start until a build passes - Missing source root: the command exits with an error. A wrong package root (a bad
extra.phem.source) prints an error, and the watcher keeps watching the application andinstalled.jsonuntil you fix it
With PHP-FPM or the Symfony local web server, you don’t need --exec: the next request uses the new build. With FrankenPHP in worker mode, the workers keep the old components in memory, so pass the server command to --exec. Set FRANKENPHP_WORKER_CONFIG="watch ./src/**/*.php" to restart the workers when a PHP class changes too.
The Flex recipe of phem/phem adds phemc watch to .symfony.local.yaml, so symfony serve runs it as a worker. Run symfony server:log to see its diagnostics:
workers:
phemc:
cmd: ['vendor/bin/phemc', 'watch', 'src']Docs and components for coding agents#
phemc docs, phemc components, phemc examples and phemc search give a coding agent the texts that it needs to write .phem code. Any agent that can run a shell command can use them. The texts match the installed versions:
- Docs: the docs of Phem are in the
phemcbinary, so they match the installedphem/phem - Components: the catalog comes from the
.phemfiles of the application and of the installed packages (vendor/). The docblocks, the props, the default values, the cases of an enum prop, and the#[Context]and#[Provide]attributes give its content - Examples and guides: a package can give its examples and a guide for agents (see Help coding agents use the components)
Each text has a stable key. A doc is its file name (events), and a section adds the anchor of its heading on the website (events#poll-the-server). A component or an example is its FQCN (Acme\Ui\Dialog). The guide of a package is the package name (acme/ui), and a section of it is acme/ui#naming.
| Command | Output |
|---|---|
phemc docs |
The docs, one line each |
phemc docs --toc |
The key and the title of each section of the docs |
phemc docs <key> |
A doc, a section with its subsections, or the guide of a package |
phemc components |
The component families of each package, one line each, and the sections of the package guides |
phemc components <name> |
One component: its docblock, its imports, its props, its context, its parts and its examples |
phemc examples |
All the examples, one line each |
phemc examples <name> |
The examples of a component, or the code of one example |
phemc search <query> |
The 20 best keys for the query, with their context |
The commands take these options:
| Option | Default | Effect |
|---|---|---|
--format <format> |
md |
md prints Markdown for the agents; json prints JSON for the tools |
--src <dir> |
src |
The source root of the application |
--package <name> |
none | phemc components and phemc examples show only this package (app for the application) |
--limit <n> |
20 |
phemc search gives n results |
--eval <file> |
none | phemc search runs a retrieval eval (see below) |
A family is the components of one file. Its root has the name of the file. A part goes inside the components of its #[Context] types, so the anatomy of a root comes from the sources:
$ phemc components Dialog
# Dialog — Acme\Ui\Dialog (acme/ui)
A modal dialog.
Import: `use Acme\Ui\Dialog; use Acme\Ui\DialogViewport; use function Acme\Ui\{DialogTrigger, DialogPopup, DialogTitle};`
Source: vendor/acme/ui/components/Dialog.phem
Also called: modal, lightbox
## Props
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultOpen | bool | false | The dialog is open on the first render. |
| title | string | required | |
| children | ?Html | null | |
| ...attrs | the other attributes | [] | |
## Anatomy
Dialog
├─ DialogPopup
└─ DialogViewport
└─ DialogPopup
Other parts: DialogTrigger, DialogTitle
## Examples
- `Acme\Ui\Examples\DialogFormDemo` Dialog with a form.phemc search is a lexical search (BM25). It reads each text with a context: the title and the headings of a doc section, or the family of a component. It splits DialogPopup into dialog and popup, it keeps a code such as E042 whole, and it finds a component by the words of its @aliases tag. The same query always gives the same result:
$ phemc search "dialog with a form"
1. `Acme\Ui\Examples\DialogFormDemo` (example) DialogFormDemo — example of Dialog (acme/ui), uses Dialog, DialogTrigger, DialogPopup, DialogTitle, Button
Dialog with a form.
2. `forms#warn-about-unsaved-changes` (doc) Handle forms › Warn about unsaved changes — This guide shows you how to get the data of a form in a handler.
A bound field that the user changed, and that the server hasn’t received yet, gets the `phem-dirty` class.A wrong key is an error with the closest keys: phemc: no component `Dialogg`. Did you mean `Acme\Ui\Dialog`, …?.
phemc search --eval <file> checks that the search finds the correct keys. The file is a YAML list of queries, each with the keys that must be in its top 20 (or --limit). The command prints the recall and the keys that it doesn’t find, and exits with code 1 under 100 %:
- query: a modal with a form
expect: [Acme\Ui\Dialog, Acme\Ui\Examples\DialogFormDemo]
- query: debounce the search input
expect:
- events#control-when-typing-sends-an-eventphemc: retrieval eval: 2 quer(ies), 3/3 key(s) in the top 20 (recall@20 100.0 %)phemc mcp#
phemc mcp runs a Model Context Protocol (MCP) server on stdin and stdout, for the coding agents (see Use Phem with coding agents). It takes two options: --project <dir> (default .), the project root, and --src <dir> (default src), the source root of the application, from the project root. To add the server to an agent, see Connect a coding agent to the MCP server.
Each tool gives the same text as its command:
| Tool | Arguments | Same as |
|---|---|---|
phem_search |
query, optional limit (1 to 100, default 20) |
phemc search <query> |
phem_doc |
optional key |
phemc docs <key>, or phemc docs --toc with no key |
phem_components |
optional package |
phemc components |
phem_component |
name, optional package |
phemc components <name> |
phem_examples |
optional name and package |
phemc examples [<name>] |
phem_check |
path, code, or both |
phemc check <file>, or phemc check - --stdin-path <path> with the code |
The server has these properties:
- Transport: one JSON-RPC 2.0 message on each line. The logs go to stderr. It knows the protocol versions
2025-06-18,2025-03-26and2024-11-05, and it gives the agent a short workflow in itsinstructions - Fresh data: it reads the project again for each call, so a tool gives the components and the code of the moment
- Read only: the tools write nothing.
phem_checkcompiles the project in memory, with thecodein place of the file ofpath, and gives the diagnostics of this file only, one line each (- 6:35 error E011: ..., with lines and columns from 1).pathmust be a relative path in the project, with no.. - Robust: a line that isn't JSON or UTF-8 gets a parse error, and a failure of one call is a tool error: the server goes on. With protocol version
2025-03-26, a batch (a JSON array of messages) gets one array of responses - Errors: a missing key (with the closest keys), a wrong argument, or a project that
phemccan't read is a tool error (isError), so the agent reads it and tries again. An unknown tool or method is a protocol error
phemc lsp#
phemc lsp runs the language server on stdin and stdout. It takes no command-line option. The editor can give the sourceDir initialization option (default src): the server checks only the .phem files in it. The server reports the same diagnostics as phemc check while you type, and it adds completion, signature help, go to definition, find references, rename, tag editing, a code lens with the usage count of each function, class and method, quick fixes (for E004, E010, E013, W004 and H001), hover and the outline of .phem files.
- Signature help: in the arguments of a call, the editor shows the parameters of the function or the method, and it marks the parameter of the argument at the cursor. It works for a PHP call (
$this->remove(,slugify(,Scientist::create(,new Scientist(), a Twig handler call (onClick={{ remove(1, | ) }}), a method of a Twig variable ({{ user.like(| ) }}), a Twig function ({{ path('app_home', | ) }}) and a Twig filter ({{ name|split(| ) }}). A named argument (force: true, andforce = truein Twig) marks its parameter. The commas of an array, a hash, a nested call and a string do not count. The signature shows the summary of the doc comment - Enum values: in the value of a backed enum prop (
<Button variant="|" />), the completion shows the values of the cases, in the order of the enum. Each item shows its case (Variant::Outline) and the doc comment of the case. The prop item writesvariant="", and the list of the values opens. The type names one enum, nullable or not, and each case has a literal value, as for E018. The enum can also be in a.phpfile - Quick fixes: add the
useimport of an unknown component (E010, one fix for each component with the name) or of an attribute (W004), change the old slot syntax<Card:footer>to<Card.footer>in the tag and in its closing tag (E013), self-close a void element (E004,<br>becomes<br />, and a</br>directly after it goes away), and remove the copy of a property (H001). No import fix shows for a qualified name (<Parts\Card>,#[\App\Component]), for a function without#[Component], for a page, for a tag whose name is a function import, or when the file imports or declares another symbol with the same short name - Find references: on a component, a function, a class, a method, a property, a prop, a slot, a class constant or an enum case, at its declaration or at a usage. A component has its tags (not the closing tags, the slot tags and the imports). A function and a method have their calls and the Twig handlers (
onClick={{ save }}). A property or a prop has its PHP names ($this->title,$titlein a function component), its Twig names ({{ title }}) and the attributes of the tags (<Card title="Hello" />). A slot also has the slot tags (<Layout.footer>, not the closing tags). A constant or a case has its PHP names (Status::Open,self::SIZE) and its Twig names ({{ Status.Open }}) - Rename: on a component, a function, a class, a method, a property, a prop, a slot, a class constant or an enum case, at its declaration or at a usage. It changes the declaration, the tags, the closing tags, the slot tags (
<Layout.footer>), the attributes of the tags (<Card title="Hello" />), theuseimports (an import with an alias keeps its alias), the PHP names ($this->title,Status::Open), the Twig names ({{ title }},{{ Status.Open }}), the class names in Twig (path(TeamPage)) and the Twig handlers (onClick={{ save }}). The rename of a prop of a function component also changes its variable in the function ($title). A method changes with the same method of its parent and child classes. A page with a default route name also changes this name inpath('app_ui_teampage')andurl('...'). The server refuses a rename that breaks the code, with a message: a declaration in a.phpfile or in a package, a component that another component replaces (#[Component(replaces: ...)]), the alias of an import (change it in theusestatement), a prop of a component that another component replaces, thechildrenslot (Phem gives the content of a tag to it by its name),render()and the magic methods, a method that a class outside the.phemfiles declares or overrides, a name that isn’t a PHP name, a component name that starts with a lowercase letter, a reserved name of PHP (E068,$this, a constantclass), a name that the namespace, the class, the file of the declaration or a file with a usage has already (an import, or a symbol of its namespace that the file uses), a property, a constant or a case that the class has already, and a parameter or a variable that the function component has already - Usages in
.phpfiles: find references, the usage count and the rename also search the.phpfiles of the project (notvendor/andvar/). A call in a controller (Initials('Ada')) is a usage, and the rename changes it and itsuse functionimport. The server reads the.phpfiles on disk, so save a.phpfile before a rename - Rename limits: the declaration must be in a
.phemfile. A name in a string or a comment doesn’t change (#[Component(replaces: 'App\Ui\Card')], a route name in PHP code, a route name with aname:argument, a Twig attribute that reads a getter:user.fullNameforgetFullName()). A named argument (new Card(title: 'x')) doesn’t change. The rename doesn’t rename the file - Tag editing: the server links the name of an open tag and the name of its closing tag (
textDocument/linkedEditingRange), so a change of one name also changes the other. It works for an HTML element, a component (<Card>), a slot tag (<Card.footer>) and a raw element (<script>). A self-closing tag, a fragment (<>) and two tags with different names have no link. Thephem/closingTagrequest (a text document and a position) gives the closing tag to add after the>of an open tag ("</Card.footer>"), ornull: in PHP code (->,$a > $b), in Twig code, in an attribute value, in a comment and after a void element (<br>), which must be self-closed. The VS Code extension and the PhpStorm plugin use it to add the closing tag as you type - Built-in controllers:
data-controller="phem-|"shows the built-in controllers. On the element of a controller, the completion shows itsdata-phem-<controller>-<name>-valueattributes. On each HTML element, it shows thedata-phem-<controller>-targetattributes, with the controllers of the elements around it first, and their parts in the value. The hover of a controller name, a part or a value shows what it is, with a link to the docs, also on the tag of a component
The VS Code and PhpStorm plugins bundle the same server compiled to WebAssembly, so they don’t need a phemc binary (see editors/vscode/README.md and editors/phpstorm/README.md). The Claude Code plugin runs the vendor/bin/phemc lsp of the application (see Use Claude Code).
The server also checks the .phem files of the Composer packages together with the application:
- Package components: completion, definition and hover work for package components in the files of the application
- Package errors: the server shows an error of a package file in that file, also at its real path for a package of a Composer path repository. Only the application that installs a package checks its files, so a linked package in the same workspace doesn’t check itself
- Reloads: the server reads the package roots and files once, then again after a Composer change, after a package file changes on disk, and when a source directory or a package root appears or goes away
- Wrong package root: when it can’t read a package root (a bad
extra.phem.source), it shows the error once (and again after a Composer change), and checks only the files of the application
Use Claude Code#
The Phem plugin for Claude Code gives Claude Code these parts of the application:
- Language server (
vendor/bin/phemc lsp): after each edit of a.phemfile, Claude Code gets thephemcerrors, warnings and hints. ItsLSPtool also gets go to definition, find references, hover and the outline - MCP server (
vendor/bin/phemc mcp): the tools ofphemc mcp - Skills:
phemloads the cheatsheet, the list of the docs (phemc docs) and the workflow (look up, write, check).phem-uiloads the components of the installed packages (phemc components) and the workflow to start from an example - Check hook: after each write or edit of a
.phemfile, the hook runsphemc check <file>. An error stops Claude (exit code 2) with the diagnostics, so it corrects the file. A warning goes to Claude as context. Another file, a project with nophemc, or a project thatphemccan't read doesn't stop Claude
Install the plugin:
claude plugin marketplace add phemphp/phem
claude plugin install phem@phemIn a running session, run /reload-plugins after the install. The plugin runs the vendor/bin/phemc of each project that has one, so use it only in projects that you trust.
The server starts the first time Claude Code edits a .phem file. After each edit, the conversation shows a summary such as Found 1 new diagnostic issues in 1 files, and Ctrl+O shows the diagnostics. If the server doesn’t start, open /plugin and read the Errors tab. For more, see editors/claude-code/README.md.
Diagnostic codes#
Errors start with E and stop the build; warnings start with W and don’t. Hints start with H: only the editors show them, often with a quick fix, and phemc build and phemc check leave them out. phemc reports these codes:
| Code | Meaning |
|---|---|
| E001–E006 | Syntax: an unclosed or mismatched tag, a void element that isn’t self-closed (E004, quick fix in the editors), more than one root, or an open tag other than <?phem (<?php, the old <?phpm, <?phemx) |
| E010–E015 | An unknown component (E010, quick fix in the editors; also a function without #[Component], or the target of a replaces), an unknown or missing prop, children or a slot that the component doesn’t accept, a slot that the tag gives two times (with a prop and a <Card.footer> tag, or with two tags), a slot tag outside the tag of its component, the old slot syntax <Card:footer> (E013, quick fix in the editors), a duplicate component (also a component named after a built-in component such as Phem\Root, or an enum that two files declare), or a required context with no provider above the component |
| E016, E017 | A replacement (#[Component(replaces: ...)]) that doesn’t accept a prop or slot of the original, requires one that the original doesn’t require, or declares a Bound prop of the original with another type. Also a replacement in a package, a second replacement of a component, a component that replaces itself, the replacement of a replacement, a page or a built-in component, a page that replaces a component, or a replaces value that isn’t Name::class or a string (self::class included) |
| E018 | A literal value of a backed enum prop that isn’t the value of a case (variant="big", level="03", an empty value or a bare attribute), when the enum is in a .phem file |
| E020 | A call to a hook function (Phem\useState, …). Phem keeps state in #[Component] classes |
| E030–E033 | An undefined variable in markup, markup in an unsupported expression (also in a prop that isn’t an Html slot), an invalid attribute, or an invalid phem:bind (not a #[State] property, not a form field, a type that can’t take the value of the field, or an aria-invalid on the field) |
| E040–E047 | A class component without render(), a readonly #[State] property, a #[Prop] property that isn’t public or is static or #[State], a second #[Prop(rest: true)] property or one whose type doesn’t accept an array, a #[Context] or #[Provide] type that isn’t one class, interface or enum (or a #[Context] property that is static, readonly, a prop or state), #[Component] on an abstract class, mount or render passed as a handler (onClick={{ mount }}), or a handler call whose arguments don’t fit the method (too many, one for an Event or a Reply parameter, a named one, or a literal of another type) |
| E050, E052, E053 | export default (not PHP; use #[Page]), the Symfony #[Route] on a function (use #[Page]) or on a class that isn’t a component, #[Broadcast] on something that isn’t a page or a component, on an error page or on a method of a page, or #[Broadcast(handlers: false)] on a page, a function component, a method, or a class with #[Broadcast] on a handler |
| E056 | A page (class or function) or an error page used as a tag |
| E057 | #[BroadcastKey] on a static property, on a constructor parameter, on a property that isn’t a #[Prop] or a #[State] in a component with #[State], on a page, or in a component with no #[Broadcast] on it or on a handler |
| E058 | #[Validated] on a function, or on a handler of a component with no non-static #[State] property of type Phem\Validation (a property of a trait or a parent class counts), or a component with more than one Validation property |
| E059, E060 | #[ErrorPage] on a class (an error page is a function), or in a package (only the application has error pages). See Error pages |
| E061 | An invalid phem:error: not a #[State] property or a Bound prop, a component with no Validation property, an element with an id, content or phem:bind, a void element, or a component tag whose component has no id prop or no children |
| E062 | A class name in markup with a case or a constant that the enum doesn’t have (OrderStatus.Canceled), or cases() of a component, when the enum is in a .phem file. See Classes in markup |
| E063 | path() or url() of a class or a function that isn’t a page with a route (path(Card), or an error page) |
| E064 | A class name in markup in another place than Class.NAME, Class.cases() or path(Page), for example {{ OrderStatus }} or OrderStatus.from('paid') |
| E065 | An invalid phem:feed: not a Feed property of the class component (a function component, a local variable that hides the property, a property of another type, or an expression), a Feed property that isn’t public or is static, readonly, promoted or nullable, or has #[State], #[Prop], #[Path] or #[Context], on the tag of a component or a <Dynamic>, on an element with an id, a spread, a phem:bind or a phem:error, or a feed element that renders more than one time (in a {% for %} loop, in an item of a feed, or a second element for the same feed) |
| E066 | Invalid content in a phem:feed element: content other than one {% for item in feed %} loop on the feed, a loop on another value, a loop with {% else %} or with a key ({% for key, item in feed %}), an item that isn’t one element (text, a Twig output, a Twig tag, or two elements), an item element with an id, or an item that reads loop or renders a class or a function component tag |
| E067 | A call of a private method in the markup of a class: Twig calls only a public method |
| E068 | A class or a function with a reserved name of PHP, which PHP cannot declare: a reserved word (Switch, List, Match, Default, Function), or for a class the name of a type (String, Int, Null) |
| W002–W003 | A list item without key, or an event that the browser doesn’t send (onMouseEnter) |
| W004 | #[Page], #[ErrorPage], #[Route], #[Component], #[State], #[Prop], #[Path], #[Context], #[Provide], #[Broadcast], #[BroadcastKey] or #[Validated] without its use import (Phem\Attribute\..., Symfony\Component\Routing\Attribute\Route). Quick fix in the editors |
| W005 | A <title> outside <head> and <svg>. The document component prints the title, and a page sets it with the title prop of the document (<Document title="Home">) |
| W006 | phem:debounce, phem:throttle, phem:prevent or phem:lock on an element with no handler, phem:key on an element with no onKeyDown or onKeyUp, phem:poll on an element with no onPoll, or onPoll on an element with no phem:poll |
| W007 | phem:live on an element with no phem:bind |
| W008 | A render() or a function component that isn’t pure: it reads a constructor service, a static property, a superglobal, the clock or a random value (see Keep render() pure) |
| H001 | A variable that only copies a property for the markup ($rows = $this). The markup reads the property. The quick fix removes the copy and uses the name of the property in the markup. A copy that keeps an older value of the property isn't a hint (see Read the properties in the markup) |
Static analysis (PHPStan)#
PHPStan can’t read a .phem file, because markup isn’t PHP. Run it on the compiled PHP in var/phem/php/ instead: that code is plain PHP with the same line numbers as the .phem file. Add the output directory to the PHPStan paths, and exclude the compiled packages, which your application can’t change:
# phpstan.dist.neon
parameters:
level: 8
paths:
- src
- var/phem/php
excludePaths:
- var/phem/php/vendorRun phemc build src first (phemc build src --no-warmup in CI). PHPStan reads only .php files, so it skips the .phem files in src/. For this .phem file:
#[Component]
function Tally(array $items): Node {
$n = count($items);
return <p id="count">{{ n }}</p>;
}phemc writes this PHP, on the same lines:
#[Component]
function Tally(array $items): Node {
$n = count($items);
return new \Phem\Element('Ui/Report/Tally.0.twig', ['n' => $n]);
}PHPStan reports the line of the .phem file in the path of the compiled file (here with --error-format=raw). Fix the error in the .phem file that the first line of the compiled file names, at the same line:
var/phem/php/Ui/Report/Tally.php:12:Function App\Ui\Report\Tally() has parameter $items with no value type specified in iterable type array.PHPStan doesn’t see two things:
- Expressions in markup (
{{ name == current }}): they’re Twig.phemc checkchecks the variables, components and props in markup - Variables that can be undefined at the markup:
phemcwrites them as$name ?? null, and the template getsnull
phemc writes $name when the variable is always defined at the markup: a parameter, a loop variable inside its loop, or an assignment in a statement before the markup (also in each branch of an if with an else, or of a try and its catch). In other code, for example an alternative syntax block (if (...): ... endif;) or after a goto label, it writes $name ?? null. If PHPStan then reports nullCoalesce.variable, assign the variable in a statement before the markup.
php-cs-fixer, PHP_CodeSniffer and Rector don’t work on .phem files, and a change in the compiled PHP doesn’t go back to the source.
Console commands#
PhemBundle adds two Symfony console commands that work on the compiled output:
| Command | Effect |
|---|---|
bin/console phem:warmup |
Compiles the phemc templates into the Twig cache. phemc build runs it, unless you pass --no-warmup |
bin/console phem:render [path] |
Prints the HTML of the page at path (/ by default) without a server. It exits with code 1 when the response isn’t successful, and doesn’t catch errors, so the console shows them with the .phem location |
bin/console debug:router lists the routes of the pages and of their events (phem_event.*).
Build directory configuration#
The compiler reads no configuration file: its options are the command-line options above. The bundle reads the output with the build_dir option, which must match --out:
# config/packages/phem.yaml
phem:
build_dir: '%kernel.project_dir%/var/phem'build_dir defaults to %kernel.project_dir%/var/phem, the same directory as the --out default. Set both when you move the output.