PHP 8 Tutorial & Reference
Types, functions, objects, superglobals, passwords, and PDO prepared statements.
PHP 8.3+ Learning Path
Follow the PHP 8 Curriculum
Read the guides in order from fundamentals to production patterns, or jump to your current skill level.
Showing closest & fuzzy matches for your search.
Embedding PHP in HTML with Standard Tags
How do I open and close PHP so HTML stays valid?
PHP Comments: Line, Block, and Docblocks
How do I comment PHP without commenting out the wrong lines?
PHP Variable Names, Assignment, and Scope Rules
What are the rules for PHP variable names, values, and scope?
PHP Types: Strings, Ints, Floats, Bools, Null, and Arrays
What are the core PHP types and how do I inspect them?
declare(strict_types=1) and Type Juggling
How do I stop PHP from silently coercing function arguments?
PHP Strings: Concatenation, Interpolation, and Multibyte Length
How do I build and measure strings safely in PHP 8?
DateTimeImmutable for Time Zones and Formatting
How do I handle dates in PHP without mutating a shared clock?
PHP Functions, Parameters, Return Types, and Defaults
How do I write a PHP function with a return type?
PHP Closures, Arrow Functions, and use()
How do I pass a small function to array_map or array_filter?
PHP Associative Arrays and Nested Records
How do I store a student record in an associative array?
array_map, array_filter, and array_column
How do I reshape a list of rows without a manual index loop?
PHP Classes, Constructors, and Property Promotion
How do I model a Student with a promoted constructor?
PHP Inheritance, Interfaces, and Contracts
When should I use an interface instead of extending a base class?
$_POST, Output Escaping, and XSS Prevention
How do I read a POST form and escape it before HTML?
password_hash and password_verify
How do I store a password so a database leak is not the password?
json_encode, json_decode, and JSON_THROW_ON_ERROR
How do I return and parse JSON in PHP without silent failures?
PHP PDO Error Mode: Exceptions Instead of Silent Failures
How should PDO report database errors in PHP 8?
PHP PDO SELECT with a Prepared Statement
How do I SELECT a row by id without concatenating SQL?
PHP PDO INSERT with Prepared Statements
How do I insert a row with PHP PDO without SQL injection?
PHP PDO UPDATE with a WHERE Clause
How do I update one row without changing the whole table?
PHP PDO DELETE with a WHERE Clause
How do I delete one row safely with PDO?
PDO Transactions: beginTransaction, commit, and rollBack
How do I insert a student and an enrollment so both succeed or neither does?
Composer and PSR-4 Autoloading
How do I autoload PHP classes with Composer instead of a pile of require calls?
PHP 8.1 Enums
How do I represent a fixed set of tracks with an enum?
PHP match Expressions
How do I map a value with match instead of switch?
The PHP Nullsafe Operator
How do I call a method when the object might be null?
PHP Exceptions and finally
How do I throw and catch a domain exception?
PHP Sessions for a Signed-In User
How do I store a user id in $_SESSION safely?
filter_var for Email and Integers
How do I validate an email and an integer with filter_var?
preg_match for a Slug
How do I test that a slug contains only lowercase letters and hyphens?
PHP Named Arguments
How do I call a function with named arguments so defaults stay clear?
PHP Union Types
How do I accept an int or a numeric string without turning types off?
PHP str_contains, str_starts_with, and str_ends_with
How do I test a string without strpos tricks?
PHP Readonly Properties
How do I stop a lesson id from being changed after construction?
PHP json_validate
How do I check a JSON string without decoding it into an array?
password_needs_rehash
How do I upgrade a stored password hash when the algorithm changes?
PHP Headers and Output
How do I send a status and a redirect before any HTML?
PHP Randomizer for Unbiased Picks
How do I pick a lesson at random without a biased modulo?
PHP Array Destructuring
How do I unpack the first two lessons from a list?
PHP Attributes
How do I attach metadata to a class without a comment parser?
PHP First-class Callables
How do I pass a function to array_map without a string name?
mb_substr for Multibyte Titles
How do I shorten a title without splitting a character?
number_format and Intl for Prices
How do I print a seat price with grouping and two decimals?
echo vs print
Should I use echo or print?
Debug with var_dump
How do I inspect a variable’s type?
PHP math helpers
How do I do min/max/round/random in PHP?
PHP type casting
How do I cast a value to another type?
PHP arithmetic operators
What are PHP math operators?
PHP comparison operators
What is == vs === in PHP?
PHP logical operators
How do I combine conditions?
Combined assignment operators
What does += mean in PHP?
if / elseif / else
How do I branch logic in PHP?
Ternary and ??
How do I assign with a short conditional?
switch statement
How do I handle many discrete cases?
while loop
How do I loop while a condition is true?
do...while loop
How do I run a loop at least once?
for loop
How do I loop with a counter?
foreach over arrays
How do I loop an array in PHP?
Default function arguments
How do I make a parameter optional?
Indexed arrays
How do I store a list in PHP?
Read $_GET values
How do I read query string data?
Read checkbox array in PHP
How do I read skills[] from a form?
Destroy a PHP session
How do I log a user out?
require db.php connection
How do I reuse one DB connection file?
Redirect with header Location
How do I send the browser to another page?
Detect GET vs POST in PHP
How do I know which HTTP method was used?
Reuse header with include
How do I share a header across pages?
Local vs global scope
Why can’t my function see an outside variable?
Static variable in a function
How do I keep a value between function calls?
Multidimensional arrays
How do I store rows of data?
Sanitize and validate input
How do I protect against XSS and bad emails?
PDO connection for Laragon MySQL
How do I connect PHP to Laragon MySQL?
PDO fetch all rows
How do I list records from MySQL?
No guides matched that search.
Try a shorter keyword, a synonym (like js or db), or remove a filter.