Modern PHP (8.2/8.3+) adds type-safety, expressiveness, and structural features that make secure code easier to write and harder to get wrong. This module covers the language features every professional PHP developer is expected to know today.
- Use the modern type system (union, intersection,
mixed,never) to make invalid states unrepresentable. - Model fixed domains with enums and immutable data with
readonly. - Understand autoloading, namespaces, traits, and the SPL that structure real applications.
- Handle failure correctly with exceptions and typed error handling.
- Union-Types — accept one of several types on a single parameter or return.
- Intersection-Types — require a value to satisfy several interfaces at once.
- Mixed-Type — the explicit "any" type and why it weakens guarantees.
- Never-Type — mark functions that always throw or exit.
- Nullsafe-Operator — short-circuit method chains on
nullsafely.
- Constructor-Property-Promotion — declare and assign constructor properties in one place.
- Readonly-Properties — write-once properties for immutable objects.
- Readonly-Classes — make every property of a class immutable at once.
- Enums — first-class enumerations for closed sets of values.
- Attributes — structured, machine-readable metadata on declarations.
- Anonymous-Classes — one-off class instances defined inline.
- Traits — horizontal code reuse across unrelated classes.
- Named-Arguments — pass arguments by name for clarity and optional-arg skipping.
- First-Class-Callable-Syntax — reference functions and methods as values with
(...). - Match-Expression — strict, expression-based branching (see Control Structures).
- Generators — lazy iteration with
yieldfor memory-efficient streams. - Fibers — cooperative, interruptible execution for async runtimes.
- Namespaces — organize code and prevent name collisions.
- Autoloading — load classes on demand (foundation for Composer PSR-4).
- Standard-PHP-Library-SPL — built-in data structures, iterators, and interfaces.
- WeakMap — associate data with objects without preventing garbage collection.
- Exceptions — the exception hierarchy and throwing/catching correctly.
- Error-Handling — error vs exception, handlers, and
declare(strict_types=1).
Every note in this module ends with hands-on Exercises. Drill them, then apply the features in the security-focused labs where modern syntax pays off:
- Lab-Insecure-Deserialization — enums and readonly value objects as a safe alternative to
unserialize(). - Lab-Building-a-REST-API — union/never types, first-class callables, and match in a real request handler.
- Module challenge: refactor one procedural script from an earlier folder to use enums, constructor promotion, readonly properties, and
match— then run it under PHPStan atmaxwith zero errors.
- Composer — dependency management built on top of PSR-4 autoloading.
- PSR Standards — the interoperability standards that shape modern PHP APIs.
- Object-Oriented-Programming-in-PHP — OOP fundamentals these features build on.