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.
Getting started — Getting Started, Configuration and Extensions, and Basic Syntax and Style.
Types and values — Types and the Type System, Type Juggling and Comparisons, Variables, Scope and Constants, Operators and Expressions, and Control Structures.
Strings, arrays and functions — Strings, Unicode, mbstring and intl, Regular Expressions, Arrays, Functions, and Closures and Callables.
Object-oriented programming — Classes and Objects, Visibility, Readonly and Asymmetric Visibility, Property Hooks, Inheritance, Interfaces and Abstract Classes, Traits, Enumerations, Magic Methods and Overloading, Cloning, Late Static Binding and Object Lifecycle, Namespaces and Autoloading, Attributes, and Reflection.
Errors, iteration and concurrency — Errors and Exceptions, Iterators and Generators, Fibers and Asynchronous PHP, and References and Memory Management.
Standard library — SPL Data Structures, Date and Time, Math, Numbers and Randomness, Files, Streams and I/O, JSON, XML and Serialization, Cryptography, Hashing and Passwords, and Command-Line PHP.
Tooling, quality and evolution — Composer and Packages, PSR Standards and Coding Style, Static Analysis and Refactoring, Testing with PHPUnit and Pest, Debugging and Profiling, OPcache, JIT and Performance, and What’s New and Migration.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.