Reserved Compiler Intrinsics
To eliminate global namespace pollution while preserving convenient developer shorthand, the Pratt parser automatically intercepts reserved intrinsics and lowers them to static Sys::* facade calls:
| Shorthand Call | Lowered AST Node | Description |
|---|---|---|
echo("text", ...$args) |
Sys::echo("text", ...$args) |
Directly compiles to Rust print!() (stdout without trailing newline) |
print("text", ...$args) |
Sys::print("text", ...$args) |
Directly compiles to Rust println!() (stdout WITH trailing newline \n) |
env('KEY', 'default') |
Sys::env('KEY', 'default') |
Read system environment variable |
dd($val1, $val2) |
Sys::dd($val1, $val2) |
Dump variables and terminate execution |
Formatting Engine & Parameters: Both
Sys::echoandSys::printdirectly map to Rust function calls (print!andprintln!) with function parameters passed as-is. RHP does not support C-style formatting (%d,%s,%f,%x, etc.). Use native Rust placeholders such as{},{:.2}(floating-point precision),{:05}(zero padding),{:x}(hexadecimal), and{:b}(binary).Note on
Sys::println: There is noSys::printlnfunction in RHP. Onlyecho(inline, no newline) andSysfacade (Sys::echoandSys::print). CallingSys::println(...)produces anUndefinedFacadeMethoderror.
Legacy PHP Function Lowering (phpFun::*)
For backward compatibility with legacy codebases, standard PHP function invocations are recognized via a compile-time static registry and automatically lowered into corresponding RHP facade methods:
| Legacy Function Call | Lowered Expression | Target Facade Implementation |
|---|---|---|
array_merge($a, $b) |
phpFun::array_merge($a, $b) |
Arr::merge($a, $b) |
strlen($str) |
phpFun::strlen($str) |
Str::byteLength($str) |
implode($glue, $arr) |
phpFun::implode($glue, $arr) |
Arr::implode($glue, $arr) |
file_get_contents($path) |
phpFun::file_get_contents($path) |
File::read($path) |
file_put_contents($path, $data) |
phpFun::file_put_contents($path, $data) |
File::write($path, $data) |
Dynamic Global Helpers (Glob::*)
Any unrecognized global function call that is not defined in userland is routed through the Glob fallback container:
// Pratt parser lowering fallback:
Expr::static_call("Glob", "customHelper", vec![callee_name, ...args])