Skip to content
Guest
← All References
PHP PHP 8.2+ / 8.3

PHP 8 Quick Reference

Essential modern PHP 8 syntax, associative arrays, match expressions, typed classes, JSON helpers, and security best practices.

declare(strict_types=1); match ($x) { ... }; fn($n) => $n * 2;

Core Syntax & Types

SyntaxPurposeExample
declare(strict_types=1);Enforce strict parameter & return typesPlace at top of PHP files
$var / "Hello $name"Variables & double-quote interpolation$title = "PHP 8";
??Null coalescing default$user = $_GET['u'] ?? 'Guest';
match ($v) { ... }Strict expression-based branchingmatch ($role) { 'admin' => 1, default => 0 }

Arrays, Classes & Web Security

API / SyntaxPurposeExample
foreach ($arr as $k => $v)Loop keys and valuesforeach ($tracks as $k => $v)
array_filter / array_mapFunctional array transformsarray_filter($xs, fn($n) => $n >= 80)
public readonly string $xConstructor property promotionInside public function __construct(...)
htmlspecialchars()Escape untrusted output (prevent XSS)htmlspecialchars($s, ENT_QUOTES, 'UTF-8')
$pdo->prepare(...)Prevent SQL injection with bound params$stmt->execute([$email]);
json_encode / json_decodeJSON API serializationjson_encode($data, JSON_THROW_ON_ERROR)

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind