PHP 8.3+

PHP 8 Tutorial & Reference

Types, functions, objects, superglobals, passwords, and PDO prepared statements.

Popular:

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 73 of 73 guides

PHP 8 Beginner

Embedding PHP in HTML with Standard Tags

How do I open and close PHP so HTML stays valid?

Language Basics 7 min
PHP 8 Beginner

PHP Comments: Line, Block, and Docblocks

How do I comment PHP without commenting out the wrong lines?

Language Basics 7 min
PHP 8 Beginner

PHP Variable Names, Assignment, and Scope Rules

What are the rules for PHP variable names, values, and scope?

Language Basics 8 min
PHP 8 Beginner

PHP Types: Strings, Ints, Floats, Bools, Null, and Arrays

What are the core PHP types and how do I inspect them?

Language Basics 8 min
PHP 8 Intermediate

declare(strict_types=1) and Type Juggling

How do I stop PHP from silently coercing function arguments?

Language Basics 9 min
PHP 8 Beginner

PHP Strings: Concatenation, Interpolation, and Multibyte Length

How do I build and measure strings safely in PHP 8?

Language Basics 8 min
PHP 8 Intermediate

DateTimeImmutable for Time Zones and Formatting

How do I handle dates in PHP without mutating a shared clock?

Language Basics 8 min
PHP 8 Beginner

PHP Functions, Parameters, Return Types, and Defaults

How do I write a PHP function with a return type?

Language Basics 8 min
PHP 8 Intermediate

PHP Closures, Arrow Functions, and use()

How do I pass a small function to array_map or array_filter?

Language Basics 9 min
PHP 8 Beginner

PHP Associative Arrays and Nested Records

How do I store a student record in an associative array?

Language Basics 7 min
PHP 8 Intermediate

array_map, array_filter, and array_column

How do I reshape a list of rows without a manual index loop?

Language Basics 8 min
PHP 8 Intermediate

PHP Classes, Constructors, and Property Promotion

How do I model a Student with a promoted constructor?

OOP 9 min
PHP 8 Advanced

PHP Inheritance, Interfaces, and Contracts

When should I use an interface instead of extending a base class?

OOP 10 min
PHP 8 Intermediate

$_POST, Output Escaping, and XSS Prevention

How do I read a POST form and escape it before HTML?

HTTP & Files 9 min
PHP 8 Intermediate

password_hash and password_verify

How do I store a password so a database leak is not the password?

PDO & Security 8 min
PHP 8 Intermediate

json_encode, json_decode, and JSON_THROW_ON_ERROR

How do I return and parse JSON in PHP without silent failures?

HTTP & Files 9 min
PHP 8 Intermediate

PHP PDO Error Mode: Exceptions Instead of Silent Failures

How should PDO report database errors in PHP 8?

PDO & Security 9 min
PHP 8 Intermediate

PHP PDO SELECT with a Prepared Statement

How do I SELECT a row by id without concatenating SQL?

PDO & Security 8 min
PHP 8 Intermediate

PHP PDO INSERT with Prepared Statements

How do I insert a row with PHP PDO without SQL injection?

PDO & Security 9 min
PHP 8 Intermediate

PHP PDO UPDATE with a WHERE Clause

How do I update one row without changing the whole table?

PDO & Security 8 min
PHP 8 Intermediate

PHP PDO DELETE with a WHERE Clause

How do I delete one row safely with PDO?

PDO & Security 8 min
PHP 8 Advanced

PDO Transactions: beginTransaction, commit, and rollBack

How do I insert a student and an enrollment so both succeed or neither does?

PDO & Security 10 min
PHP 8 Advanced

Composer and PSR-4 Autoloading

How do I autoload PHP classes with Composer instead of a pile of require calls?

OOP 9 min
PHP 8 Intermediate

PHP 8.1 Enums

How do I represent a fixed set of tracks with an enum?

OOP 7 min
PHP 8 Intermediate

PHP match Expressions

How do I map a value with match instead of switch?

Language Basics 7 min
PHP 8 Intermediate

The PHP Nullsafe Operator

How do I call a method when the object might be null?

Language Basics 7 min
PHP 8 Intermediate

PHP Exceptions and finally

How do I throw and catch a domain exception?

Language Basics 8 min
PHP 8 Intermediate

PHP Sessions for a Signed-In User

How do I store a user id in $_SESSION safely?

HTTP & Files 8 min
PHP 8 Intermediate

filter_var for Email and Integers

How do I validate an email and an integer with filter_var?

HTTP & Files 7 min
PHP 8 Intermediate

preg_match for a Slug

How do I test that a slug contains only lowercase letters and hyphens?

Language Basics 7 min
PHP 8 Intermediate

PHP Named Arguments

How do I call a function with named arguments so defaults stay clear?

Language Basics 7 min
PHP 8 Intermediate

PHP Union Types

How do I accept an int or a numeric string without turning types off?

Language Basics 6 min
PHP 8 Beginner

PHP str_contains, str_starts_with, and str_ends_with

How do I test a string without strpos tricks?

Language Basics 6 min
PHP 8 Intermediate

PHP Readonly Properties

How do I stop a lesson id from being changed after construction?

OOP 6 min
PHP 8 Intermediate

PHP json_validate

How do I check a JSON string without decoding it into an array?

HTTP & Files 6 min
PHP 8 Intermediate

password_needs_rehash

How do I upgrade a stored password hash when the algorithm changes?

PDO & Security 6 min
PHP 8 Intermediate

PHP Headers and Output

How do I send a status and a redirect before any HTML?

HTTP & Files 6 min
PHP 8 Intermediate

PHP Randomizer for Unbiased Picks

How do I pick a lesson at random without a biased modulo?

Language Basics 6 min
PHP 8 Beginner

PHP Array Destructuring

How do I unpack the first two lessons from a list?

Language Basics 6 min
PHP 8 Advanced

PHP Attributes

How do I attach metadata to a class without a comment parser?

OOP 6 min
PHP 8 Intermediate

PHP First-class Callables

How do I pass a function to array_map without a string name?

Language Basics 6 min
PHP 8 Intermediate

mb_substr for Multibyte Titles

How do I shorten a title without splitting a character?

Language Basics 6 min
PHP 8 Beginner

number_format and Intl for Prices

How do I print a seat price with grouping and two decimals?

Language Basics 6 min
PHP 8 Beginner

echo vs print

Should I use echo or print?

Basics 1 min
PHP 8 Beginner

Debug with var_dump

How do I inspect a variable’s type?

Debugging 1 min
PHP 8 Beginner

PHP math helpers

How do I do min/max/round/random in PHP?

Basics 1 min
PHP 8 Beginner

PHP type casting

How do I cast a value to another type?

Basics 1 min
PHP 8 Beginner

PHP arithmetic operators

What are PHP math operators?

Basics 1 min
PHP 8 Beginner

PHP comparison operators

What is == vs === in PHP?

Basics 1 min
PHP 8 Beginner

PHP logical operators

How do I combine conditions?

Basics 1 min
PHP 8 Beginner

Combined assignment operators

What does += mean in PHP?

Basics 1 min
PHP 8 Beginner

if / elseif / else

How do I branch logic in PHP?

Basics 1 min
PHP 8 Beginner

Ternary and ??

How do I assign with a short conditional?

Basics 1 min
PHP 8 Beginner

switch statement

How do I handle many discrete cases?

Basics 1 min
PHP 8 Beginner

while loop

How do I loop while a condition is true?

Basics 1 min
PHP 8 Beginner

do...while loop

How do I run a loop at least once?

Basics 1 min
PHP 8 Beginner

for loop

How do I loop with a counter?

Basics 1 min
PHP 8 Beginner

foreach over arrays

How do I loop an array in PHP?

Basics 1 min
PHP 8 Beginner

Default function arguments

How do I make a parameter optional?

Basics 1 min
PHP 8 Beginner

Indexed arrays

How do I store a list in PHP?

Basics 1 min
PHP 8 Beginner

Read $_GET values

How do I read query string data?

Forms 1 min
PHP 8 Beginner

Read checkbox array in PHP

How do I read skills[] from a form?

Forms 1 min
PHP 8 Beginner

Destroy a PHP session

How do I log a user out?

Auth 1 min
PHP 8 Beginner

require db.php connection

How do I reuse one DB connection file?

Database 1 min
PHP 8 Beginner

Redirect with header Location

How do I send the browser to another page?

Basics 1 min
PHP 8 Beginner

Detect GET vs POST in PHP

How do I know which HTTP method was used?

Forms 1 min
PHP 8 Beginner

Reuse header with include

How do I share a header across pages?

Basics 1 min
PHP 8 Intermediate

Local vs global scope

Why can’t my function see an outside variable?

Basics 1 min
PHP 8 Intermediate

Static variable in a function

How do I keep a value between function calls?

Basics 1 min
PHP 8 Intermediate

Multidimensional arrays

How do I store rows of data?

Basics 1 min
PHP 8 Intermediate

Sanitize and validate input

How do I protect against XSS and bad emails?

Security 1 min
PHP 8 Intermediate

PDO connection for Laragon MySQL

How do I connect PHP to Laragon MySQL?

Database 1 min
PHP 8 Intermediate

PDO fetch all rows

How do I list records from MySQL?

Database 1 min

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…