Code written for PHP 5.6 still runs. That is the problem. No types, switch with forgotten break, isset() chains five levels deep. PHP 8 removes whole classes of bugs, but one enum in a plugin with Requires PHP: 7.4 breaks real sites. This module shows both sides.
| Course | PHP for WordPress Developers · Module 2 of 9 · Stage 1 "Language" |
| Learn | Types, match, nullsafe, enum, readonly and what each one requires from the host |
| How | Short lessons with code from real plugins, IDE practice in the browser, interview questions after every lesson |
The idea in one picture
flowchart LR
L["Legacy 7.x<br/>for comparison only"] -.-> B["PHP 8.0<br/>union · match · nullsafe"]
B --> C["PHP 8.1<br/>enum · readonly"]
C --> N["8.2 → 8.5<br/>what each release adds"]
N --> D["Requires PHP<br/>in the plugin header"]
classDef step fill:#f5f3ff,stroke:#777BB4,color:#1e1b4b
classDef key fill:#777BB4,stroke:#4f5b93,color:#ffffff
Every feature has a minimum version. The plugin header says which one your users need.
Before → after
| Before | After Module 2 |
|---|---|
| Untyped arguments and silent bugs | Types and declare(strict_types=1) catch them early |
switch with a missing break | match returns a value and has no fall-through |
isset($a['b']['c']) chains | Nullsafe ?-> and the ?? operator |
| Class constants as fake enums | Native enum |
You'll be able to answer
- What does
declare(strict_types=1)change and where does it apply? - How does
matchdiffer fromswitch? - How do you use PHP 8.1 features in a plugin that must run on older PHP?