PHP quick reference

Runs in Zerethon IDE · PHP 8.4 Official PHP documentation ↗

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 with echo.

  • Variables and types

    Variables start with $; int, float, string, bool, null, arrays; strict comparison and conversions.

  • Conditions and loops

    if / elseif, the match expression, foreach, for and while.

  • Functions

    Typed parameters and return types, defaults, named arguments, arrow functions and closures.

  • Classes, enums and readonly

    Classes with constructor promotion, readonly properties, interfaces and enums.

Data

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() and fgetcsv; 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 TypeError and “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.

References