PHP quick reference
PHP 8.4 on the command line: echo and types, control flow and match, typed functions, arrays, strings and regular expressions, classes, input and files — and how a PHP script runs in Zerethon IDE.
Written for PHP 8.4. Examples that show an output were run in the Zerethon sandbox (PHP 8.4) on 2026-10-20.
Basics
-
Hello, World
A PHP script starts with
<?php; print withecho. -
Variables and types
Variables start with
$; int, float, string, bool, null, arrays; strict comparison and conversions. -
Conditions and loops
if/elseif, thematchexpression,foreach,forandwhile. -
Functions
Typed parameters and return types, defaults, named arguments, arrow functions and closures.
-
Classes, enums and readonly
Classes with constructor promotion,
readonlyproperties, interfaces and enums.
Data
-
Arrays and sorting
Lists and associative arrays, the array functions you use most, and the sort functions.
-
Strings and regular expressions
String functions,
sprintf,explode/implode, multibyte text withmb_*, andpreg_*regular expressions.
Input and files
-
Reading input (stdin)
Read what you type in the IDE's Input tab with
fgets(STDIN)or all at once. -
Reading and writing files
Read project files with
file_get_contents,file()andfgetcsv; write temporary files under/tmp. -
Several files
Load your other files with
require; Composer packages are not available.
In Zerethon IDE
-
Running PHP in Zerethon IDE
How Run starts your script with the PHP 8.4 CLI, how errors are shown, the time limit, input and tests.
-
Common errors
Warnings such as “Undefined variable” and fatal errors such as
TypeErrorand “Call to undefined function”. -
Official documentation
Where to read more: the PHP manual on php.net — the language reference and a page for every function.