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.

How to use this page: Read the explanation first, then follow the example from top to bottom. Each lesson has a practice task with an optional solution. The editor lets you change and copy the example; open the Playground to compile and run code in your browser. To run programs locally, install the compiler, save a .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!

hello.hphp
Run with: hphp run hello.hphp

Try it locally:

echo 'echo "Hello, HolyPHP!";' > hello.hphp
hphp run hello.hphp
Practice · lesson 1Personalize your first program. Change the name and welcome message, save it as 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

types.hphp
Run with: hphp run types.hphp
Practice · lesson 2Create a profile. Set your name, add a city, and print both values. Then add a typed $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.

functions.hphp
Run with: hphp run functions.hphp
By-reference parameters: Use &$param to modify the caller's variable. The argument must be a variable, not an expression.
Practice · lesson 3Write a function. Write 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).

control.hphp
Run with: hphp run control.hphp
Practice · lesson 4Print even numbers. Use a 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!

arrays.hphp
Run with: hphp run arrays.hphp

Common array functions: count(), array_push(), array_pop(), sort(), array_map(), array_filter(), implode(), explode()

Practice · lesson 5Grow a shopping list. Create an array with two fruits, append a third, print its count, then print every fruit with 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.

classes.hphp
Run with: hphp run classes.hphp
Visibility: pub for public, private for private. No protected keyword mentioned in the docs, check the language reference.
Practice · lesson 6Build a counter. Create a 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)

borrowing.hphp
Run with: hphp run borrowing.hphp
Important: The borrow checker prevents data races at compile time. You cannot have mutable and immutable borrows at the same time, and use-after-move is rejected. These errors are caught by 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
Practice · lesson 7Update a value safely. Write 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; // 15

8 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!

ide - HolyIDE

Full IDE for HolyPHP written in HolyPHP itself

hphp run holyide/holyide.hphp

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

CommandPurpose
hphp run file.hphpCompile and run
hphp build file.hphp -o app.exeBuild standalone executable
hphp check file.hphpType and borrow check only
hphp emit file.hphpInspect internal representation
hphp pkg search/installPackage management

Next Steps

Practice · lesson 8Take your next step. Choose an example, save a copy as a .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.hphp
hphp run my-example.hphp
hphp build my-example.hphp -o my-app
Pro tip: Use hphp check often! The borrow checker will catch memory errors at compile time, saving you from runtime bugs.