PHP Cheat Sheet

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

The reference material consulted while preparing these pages is listed in the section bibliography.

A single-page, colour-coded summary of the PHP language, written against PHP 8.5 (8.5.11), with additions from 8.0 onwards labelled by version and upcoming 8.6 items marked (versions verified 2026-10-05) — PHP tags and CLI one-liners, the type list and declarations (union, intersection and DNF types, nullable, never, strict_types), the PHP 8 comparison and juggling rules, operators (??, ??=, <=>, ?->, |>, ...), control flow including match, string and array one-liners (including array_find() and array_first()), functions (named arguments, variadics, by-reference parameters), closures, arrow functions and first-class callables, a class skeleton showing constructor promotion, readonly, asymmetric visibility and property hooks, interfaces, abstract classes, traits and enums, magic methods, the predefined attributes, the exception hierarchy with try/catch/finally, generators and fibers, namespaces and use, date/time, JSON and file one-liners, password_hash() and sodium, Composer commands and the composer.json autoload block, the PSR list, PHPUnit and Pest snippets, and a strip of what changed since older tutorials — handy for quick memorization or as a downloadable PDF desk reference.

For the full explanation, every option, and additional examples, see the dedicated pages:

Start here — PHP Reference.