Interactive HolyPHP Guide
Learn HolyPHP one small idea at a time. Read a short explanation, study an editable example, then solve a practice task. Use the Playground to run code in your browser or install the compiler to run it on your computer.
.hphp file and use hphp run file.hphp.
Learning Path
1 Hello World
HolyPHP feels just like PHP — start writing code without boilerplate. No main() function required!
Try it locally:
echo 'echo "Hello, HolyPHP!";' > hello.hphp
hphp run hello.hphp
hello.hphp, then run hphp run hello.hphp.Show one possible solution
Put text in quotes. Write {$name} inside a quoted string to insert that variable's value.
$name = "Alex";echo "Hello, HolyPHP!";echo "Welcome, {$name}! I am learning to code.";2 Variables & Types
Variables start with $ like PHP. Types are inferred, but you can add explicit types when you want.
Inferred Types
$x = 42; — compiler infers int
$s = "hello"; — compiler infers string
Explicit Types
$x: int = 42; — pinned to int
$f: float = 3.14; — pinned to float
Available Types
int, float, bool, string, array, mixed, void
$days: int = 7; variable and print it.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
$name = "Ada";$city = "Zurich";$days: int = 7;echo "{$name} lives in {$city}. Practice days: {$days}";3 Functions
Functions can be typed or untyped. Like PHP, they support default parameters and pass by reference.
&$param to modify the caller's variable. The argument must be a variable, not an expression.
double(int $number): int. Return twice the number, then call it with 6 and 21.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
function double(int $number): int { return $number * 2; }echo double(6);echo double(21);4 Control Flow
HolyPHP has if/else, while, for, foreach, and the powerful match expression (like Rust/PHP 8).
for loop to print 2, 4, 6, 8 and 10. Start at 2, stop at 10 and add 2 each time.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
for ($number = 2; $number <= 10; $number += 2) { echo "{$number}";}5 Arrays & Maps
Arrays are versatile in HolyPHP — they can be indexed lists or associative maps. Copy-on-write semantics like PHP!
Common array functions: count(), array_push(), array_pop(), sort(), array_map(), array_filter(), implode(), explode()
foreach.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
$fruits = ["apple", "banana"];$fruits[] = "orange";echo count($fruits);foreach ($fruits as $fruit) { echo "- {$fruit}"; }6 Classes & Objects
Object-oriented programming with visibility modifiers, constructors, and inheritance.
pub for public, private for private. No protected keyword mentioned in the docs, check the language reference.
Counter class with public integer $value, initialize it to 0, and add an increment() method.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
class Counter { pub int $value; pub function __construct() { $this->value = 0; } pub function increment(): void { $this->value += 1; }}$counter = new Counter(); $counter->increment(); echo $counter->value;7 Memory Safety - Borrow Checker & Ownership
This is what makes HolyPHP special! Compile-time memory safety without garbage collection.
Ownership (own<T>)
Exclusive ownership, moved on assignment
Use-after-move is a compile error
Borrowing (&)
Immutable borrow: many readers
Mutable borrow (&mut): one writer only
Smart Pointers
own<T> - owned, moves
Rc<T> - reference counted
*T - raw pointer (unsafe only)
hphp check.
Try these patterns to understand the rules:
// This would be a COMPILE ERROR:
// $a = 5;
// $b = &$a;
// $a += 1; // cannot assign while borrowed
addFive(int &$value): void, call it with a variable set to 10, and print the value after the call.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
function addFive(int &$value): void { $value += 5; }$score = 10;addFive($score);echo $score; // 158 Going Further
HolyPHP comes with powerful built-in libraries and tools. Explore them!
Built-in Libraries
ui - Desktop GUI
Native Win32 GUI with themes, widgets, and auto-layout
import "ui";
$app = new App("Hello");
$app->button("Click", "primary", function(){ echo "Hi!"; });
$app->run();
html - HolyHTML Engine
HTML/CSS parser, layout engine, and painter
Render web-like UIs natively without a browser!
async - Event Loop
Cooperative async with timers, sockets, HTTP
thread - Concurrency
Real OS threads with channels, mutexes, atomics
websocket - RFC 6455
WebSocket server, browser-compatible
Essential CLI Commands
| Command | Purpose |
|---|---|
hphp run file.hphp | Compile and run |
hphp build file.hphp -o app.exe | Build standalone executable |
hphp check file.hphp | Type and borrow check only |
hphp emit file.hphp | Inspect internal representation |
hphp pkg search/install | Package management |
Next Steps
- Try the Playground — Interactive IDE-style environment
- Browse Examples — Real programs from the repository
- Language Reference — Complete language documentation
- Built-in Functions — All 305 functions
- CLI Documentation — Toolchain details
.hphp file, explain what its variables store, change one message, then check and run it.Show one possible solution
Try the steps yourself first. Then compare this small example with your code:
hphp check my-example.hphphphp run my-example.hphphphp build my-example.hphp -o my-apphphp check often! The borrow checker will catch memory errors at compile time, saving you from runtime bugs.