Chapter 3: Hello, World!
Let's write our very first HolyPHP program. It's traditional to start with "Hello, World!".
Creating the File
Create a new file called hello.hphp with your favorite text editor.
Writing the Code
echo "Hello, World!";
That's it! No imports, no main() function, no boilerplate. You can just start writing code.
Running the Program
Open your terminal in the same directory as hello.hphp and run:
hphp run hello.hphp
You should see:
Hello, World!
Understanding the Code
echo- Outputs text to the screen (like in PHP)echoadds a line break after its output automatically, so you do not need to append"\n".;- Statement terminator (like in PHP and JavaScript)
Building a Standalone Executable
Want to share your program? Compile it to a standalone executable:
hphp build hello.hphp -o hello
Now you can run it directly:
./hello # On Linux/Mac
hello.exe # On Windows
No HolyPHP compiler needed on the target machine!
A Slightly More Interesting Example
$name = "World";
echo "Hello, {$name}!";
Notice the string interpolation with {$name} - just like PHP! Variables start with $.
Try it yourself! Change the message or add more
echo statements. Experiment and see what happens.
Challenge: Write a program that prints your name, age, and favorite programming language on separate lines.