Documentation · Chapter 10

Translate PHP into browser instructions.

Only a documented subset of PHP closures is compiled. Unsupported code fails clearly instead of being evaluated dynamically.

Every lesson starts from the problem, explains the mechanism, then gives a concrete verification.

Natural PHP and explicit actions

Simple mutations such as ++, --, assignments, arithmetic, ternaries, if/else, arrays, and supported function calls can remain natural PHP. ClientAction remains available for explicit composition.

phpaml — zsh
Button('Add')->onClick(fn () => $this->count++);
Button('Reset')->onClick(ClientAction::set('count', 0));

State references remain live

StateRef points to the current browser value. It avoids freezing the server-rendered value inside later operations.

Conditions and collections

When, loops, array append/remove/sort, and compiled PHP conditions update only the relevant UI bindings.