4: Syntax & Structuur
Phlo transpileert .phlo bronbestanden naar gewone PHP-klassen en gegenereerde assets. De syntaxis is PHP-achtig, maar zonder puntkomma's aan het einde van statements.
4.1: Bestandstructuur
Een .phlo-bestand kan top-level controllercode en knooppunten bevatten:
routefunctionpropstaticmethodview<style><script>
Voorbeeld:
route both GET home => view($this)
prop title = 'Welcome'
view:
<h1>$this->title</h1>4.2: Statements and the line parser
Statements end at a line break, not at a semicolon:
$count = 1
if ($active) $count++
This works because the transpiler appends a ; to every line and only removes it where the line clearly continues. The full rule set:
- Every line gets a
;at the end. - That
;is removed when the line ends with(,[,{,},,or.. These are implicit continuations: an opening bracket, a trailing comma in an argument list, or a concatenation that breaks after the.. - A line that ends with a single backslash
\is an explicit continuation: the parser removes the backslash and the semicolon and joins the line with the next one. Use this for anything that does not fall under the implicit set, such as a multiline ternary:
$label = $visitors === 1 \
? 'visitor' \
: 'visitors'
- Empty lines never get a
;.
The mental model: stop thinking about semicolons entirely. Only ask "is my statement complete on this line?" If not, end the line with one of ( [ { , . (which happens naturally in most multiline code) or with an explicit \.
Without an implicit or explicit continuation, every line becomes its own statement. That is why in multiline calls every argument line must end with a comma, including the last one:
apply (
title: 'Done',
main: '<p>Ready</p>',
)
Lesson. A multiline node body ends at the line that closes what its first line left open, in reverse order:prop x => [closes with],strtr($x, [closes with]), andarr(foo(1), [closes with])as well, because thefoo(1)pair is already closed on the first line. The closing line holds those closers and nothing else. A body that never meets its closing line is a build error (Unclosed node body at <file>:<line>), so the rest of the file can no longer disappear into it.
4.3: Controller code
Code op het hoogste niveau dat geen node is, wordt controllercode van de gegenereerde klasse. Die code wordt uitgevoerd wanneer de instantie voor het eerst wordt opgehaald.
prop ready = false
$this->ready = true
Gebruik controller code voor lichte initialisatie. Plaats de verzoeklogica in routes en methoden.
4.4: Instanties
Gebruik %name om een Phlo-object op te halen via de instance manager:
%payload->name
%session->user
%creds->mysql->database
De instantie wordt lui aangemaakt en vervolgens hergebruikt binnen het verzoek.
Les. De transpiler herschrijft%nameOVERAL in een.phlo-bestand, inclusief binnen stringliteral. Een pagina die de letterlijke tekst%sessionprobeerde af te drukken in een codevoorbeeld verzondphlo('session')naar zijn bezoekers. Voorbeeldcode die letterlijk moet blijven, behoort in externe bestanden (.txt,.md) die tijdens runtime worden geladen, nooit in.phlostringliteral.
4.5: Props
Statische prop:
prop title = 'App'
Berekenende prop:
prop fullName => $this->first.' '.$this->last
Berekenbare props worden gegenereerd als getters en kunnen als een eigenschap worden gelezen:
$this->fullName4.6: Methoden
Enkele regel methode:
method label($value) => ucfirst($value)
Multiline methode:
method label($value){
if (!$value) return void
return ucfirst($value)
}4.7: Functies
Je definieert globale functies met function:
function initials($name){
return strtoupper(substr($name, 0, 1))
}
Gebruik dit spaarzaam. Voor app-code is een reguliere app-klasse meestal beter; alleen framework-brede helpers horen in een runtime resource thuis.
4.8: Statica
Statische waarde:
static table = 'users'
Statische methode:
static label($value) => ucfirst($value)
Oproep:
user::label('jordi')4.9: Strings en operatoren
Strings en operatoren volgen PHP:
$name = 'Jordi'
$title = "Hello $name"
$active = $count > 0 && !$archived
Gebruik void voor een lege string wanneer dat de intentie duidelijk maakt.
4.10: Benamde argumenten
Genomineerde argumenten werken zoals in PHP en houden aanroepen leesbaar:
%DB->load (
table: 'users',
where: 'active=1',
order: 'name',
)4.11: Foutafhandeling en JSON-antwoorden
error('message', $code = 500) beëindigt een verzoek met een status. Het gooit (geen return nodig), en de engine rendert het om aan het verzoek te voldoen:
- een async/SPA verzoek krijgt
apply(error: 'message')(phlo.js toont het); - een JSON context (de route die
%security->apiaanroept, of de client stuurdeAccept: application/json) krijgt een JSON body{"error": "message"}met de statuscode; - anders de HTML foutpagina (de volledige debugpagina wanneer
debug: true, een minimale pagina anders).
if (!$record) error('Record not found', 404)
Klantfouten ($code < 500) behouden hun bericht; serverfouten (>= 500) blijven algemeen ("Error") tenzij debug: true, zodat interne onopgevangen uitzonderingen standaard niet worden blootgesteld.
Voor een succesvolle JSON-respons gebruik je output($data, code:): een array wordt automatisch gecodeerd en code stelt de status in. Een JSON API route gebruikt daarom output() voor resultaten en error() voor mislukkingen, zonder een per-app responswrapper.
debug: true (instellen in www/app.php) schakelt gedetailleerde debug-uitvoer in; runtime-fouten worden gelogd naar data/errors.json.
Laatst bijgewerkt op 28-10-2026