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.
1. Modern PHP Syntax & Types
The PHP 8 language features you use every day: strict types, union types, named arguments, match, nullsafe and more.
- Getting Started with PHP 8 — Install PHP 8.x, run scripts and a dev server, and enable strict types from day one.
- The PHP 8 Type System — Scalar, union, nullable, intersection, mixed, never and DNF types.
- Named Arguments, Defaults and Spread — Call functions by parameter name, skip defaults, and unpack arrays into arguments.
- match, Nullsafe and Modern Operators — Use match expressions, the nullsafe operator and null coalescing to write concise, safe code.
- Functions, Closures and First-Class Callables — Arrow functions, closures, first-class callable syntax and modern array helpers.
- 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.
- Classes, Constructor Promotion and readonly — Write compact, immutable classes with promoted constructor properties and readonly.
- Interfaces, Abstract Classes and Traits — Model contracts and share behavior without deep inheritance hierarchies.
- Enums — Use pure and backed enums to replace magic strings and class constants.
- Property Hooks and Asymmetric Visibility (PHP 8.4) — Replace boilerplate getters/setters with property hooks and public-read, private-write properties.
- 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.
- Exceptions and the Throwable Hierarchy — Understand Error vs Exception, custom exceptions, finally and exception chaining.
- Application-Wide Error Handling — Configure error reporting, convert warnings, and render safe error responses.
- Input Validation and Value Objects — Validate at the boundary and model domain rules with small immutable types.
- 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.
- Composer Essentials — Install and update dependencies safely with composer.json and composer.lock.
- Namespaces and PSR-4 Autoloading — Organize code with namespaces and let Composer load classes automatically.
- PSR Standards You Should Know — PSR-3 logging, PSR-7/15/17/18 HTTP, PSR-11 containers, PSR-20 clocks and PER coding style.
- 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.
- Connecting with PDO — Create a correctly configured PDO connection with exceptions and sane defaults.
- Prepared Statements and Safe Queries — Prevent SQL injection with bound parameters, including IN lists and dynamic sorting.
- Transactions and Concurrency — Group writes atomically and avoid race conditions with locks and conditional updates.
- Repositories and Data Mapping — Separate SQL from business logic with repositories that return domain objects.
- 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.
- Passwords and Authentication — Hash passwords with password_hash, verify them safely and rehash as algorithms improve.
- Sessions and Cookies — Configure secure sessions and cookies for PHP apps.
- XSS and Output Escaping — Escape output by context and use templates that auto-escape.
- CSRF Protection and Secure Forms — Protect state-changing requests with tokens, SameSite cookies and method discipline.
- 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.
- Unit Testing with PHPUnit — Write fast, focused tests with PHPUnit 11 attributes and data providers.
- Test Doubles and Integration Tests — Use stubs, mocks and fakes wisely, and test database code against a real database.
- Static Analysis with PHPStan and Psalm — Find bugs before running code and adopt strict levels gradually.
- 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.
- OPcache, Preloading and the JIT — Configure OPcache for production and understand when the JIT helps.
- PHP-FPM and Nginx — Run PHP behind Nginx with a tuned FPM process pool.
- Docker for PHP Applications — Build lean, secure production images with multi-stage Dockerfiles.
- Profiling and Caching — Find bottlenecks with profilers and speed up apps with APCu, Redis and HTTP caching.