Free course · 37 lessons · Intermediate

PHP 8: Modern PHP Development

From PHP 8 syntax and types to enums, property hooks, Composer, PDO, security, testing and production deployment with OPcache, FPM and Docker.

Start the course

1. Modern PHP Syntax & Types

The PHP 8 language features you use every day: strict types, union types, named arguments, match, nullsafe and more.

  1. Getting Started with PHP 8 — Install PHP 8.x, run scripts and a dev server, and enable strict types from day one.
  2. The PHP 8 Type System — Scalar, union, nullable, intersection, mixed, never and DNF types.
  3. Named Arguments, Defaults and Spread — Call functions by parameter name, skip defaults, and unpack arrays into arguments.
  4. match, Nullsafe and Modern Operators — Use match expressions, the nullsafe operator and null coalescing to write concise, safe code.
  5. Functions, Closures and First-Class Callables — Arrow functions, closures, first-class callable syntax and modern array helpers.
  6. Generators and Iterables — Process large data sets lazily with yield, keys and generator delegation.

2. Object-Oriented PHP 8

Classes with promoted and readonly properties, interfaces, traits, enums, property hooks and attributes.

  1. Classes, Constructor Promotion and readonly — Write compact, immutable classes with promoted constructor properties and readonly.
  2. Interfaces, Abstract Classes and Traits — Model contracts and share behavior without deep inheritance hierarchies.
  3. Enums — Use pure and backed enums to replace magic strings and class constants.
  4. Property Hooks and Asymmetric Visibility (PHP 8.4) — Replace boilerplate getters/setters with property hooks and public-read, private-write properties.
  5. Attributes — Add structured metadata to classes and methods and read it with Reflection.

3. Errors, Exceptions and Robust Code

Handle failures predictably with exceptions, centralized error handling and validated domain objects.

  1. Exceptions and the Throwable Hierarchy — Understand Error vs Exception, custom exceptions, finally and exception chaining.
  2. Application-Wide Error Handling — Configure error reporting, convert warnings, and render safe error responses.
  3. Input Validation and Value Objects — Validate at the boundary and model domain rules with small immutable types.
  4. Dates, Time Zones and Immutability — Work safely with DateTimeImmutable, time zones and intervals.

4. Composer, Autoloading and PSR Standards

Manage dependencies, structure namespaces, and follow the PHP-FIG standards used by every framework.

  1. Composer Essentials — Install and update dependencies safely with composer.json and composer.lock.
  2. Namespaces and PSR-4 Autoloading — Organize code with namespaces and let Composer load classes automatically.
  3. PSR Standards You Should Know — PSR-3 logging, PSR-7/15/17/18 HTTP, PSR-11 containers, PSR-20 clocks and PER coding style.
  4. Dependency Injection and Containers — Wire services through constructors and let a container build object graphs.

5. Databases with PDO

Connect, query safely, use transactions and structure data access in PHP 8.

  1. Connecting with PDO — Create a correctly configured PDO connection with exceptions and sane defaults.
  2. Prepared Statements and Safe Queries — Prevent SQL injection with bound parameters, including IN lists and dynamic sorting.
  3. Transactions and Concurrency — Group writes atomically and avoid race conditions with locks and conditional updates.
  4. Repositories and Data Mapping — Separate SQL from business logic with repositories that return domain objects.
  5. Migrations and ORMs (Doctrine, Eloquent) — Version your schema and know when an ORM helps or hurts.

6. Security for PHP Applications

Protect users and data: passwords, sessions, XSS, CSRF, uploads and secrets.

  1. Passwords and Authentication — Hash passwords with password_hash, verify them safely and rehash as algorithms improve.
  2. Sessions and Cookies — Configure secure sessions and cookies for PHP apps.
  3. XSS and Output Escaping — Escape output by context and use templates that auto-escape.
  4. CSRF Protection and Secure Forms — Protect state-changing requests with tokens, SameSite cookies and method discipline.
  5. File Uploads, Input Hardening and Secrets — Handle uploads safely and keep credentials out of code.

7. Testing and Tooling

PHPUnit, test doubles, static analysis, code style and CI for PHP projects.

  1. Unit Testing with PHPUnit — Write fast, focused tests with PHPUnit 11 attributes and data providers.
  2. Test Doubles and Integration Tests — Use stubs, mocks and fakes wisely, and test database code against a real database.
  3. Static Analysis with PHPStan and Psalm — Find bugs before running code and adopt strict levels gradually.
  4. Code Style, Automated Refactoring and CI — Automate formatting with PHP-CS-Fixer, upgrades with Rector, and checks in CI.

8. Performance and Deployment

OPcache, PHP-FPM, Docker, profiling and caching for production PHP.

  1. OPcache, Preloading and the JIT — Configure OPcache for production and understand when the JIT helps.
  2. PHP-FPM and Nginx — Run PHP behind Nginx with a tuned FPM process pool.
  3. Docker for PHP Applications — Build lean, secure production images with multi-stage Dockerfiles.
  4. Profiling and Caching — Find bottlenecks with profilers and speed up apps with APCu, Redis and HTTP caching.