PHP 8.0 is a major release with new syntax, a JIT compiler, and a stricter type system. Here are the highlights that change day-to-day code, plus notes on upgrading WordPress projects.
1. The JIT compiler
Normally PHP compiles to opcodes run on a virtual machine. The just-in-time compiler can emit native machine code and run it directly on the CPU. It's a big win for CPU-heavy, math-style workloads — but for typical I/O-bound web apps the difference is modest. It's off by default.
2. Nullsafe operator
Chain calls without manual null checks:
// Before
$country = null;
if ($session !== null) {
$user = $session->user;
if ($user !== null) {
$address = $user->getAddress();
if ($address !== null) {
$country = $address->country;
}
}
}
// PHP 8
$country = $session?->user?->getAddress()?->country;
3. Named arguments
Pass arguments by name and skip optional ones:
htmlspecialchars($string, double_encode: false);
4. Union types
Declare more than one type natively instead of in docblocks:
public function setId(int|string $id): void {}
5. Constructor property promotion
Less boilerplate for value objects:
// PHP 8
class Comment {
public function __construct(
public string $title,
public string $body,
) {}
}
6. Match expression
Like switch, but an expression, with strict comparison and no fall-through:
$result = match($status) {
200, 201 => 'success',
404 => 'not found',
default => 'unknown',
};
7. Attributes
Structured, native metadata in place of docblock annotations:
#[Route('/api/users', methods: ['GET'])]
public function list() {}
WordPress compatibility
WordPress core runs on PHP 8, but plugins and themes are the risk. Many older plugins use patterns PHP 8 now treats more strictly (e.g. passing null where a string is expected, or removed/changed functions). Test on a staging site, enable debugging, and update plugins before moving production.
Deprecations to watch
- Stricter type juggling — some loose comparisons changed behavior.
- Several long-deprecated functions and the
@-silenced fatal patterns no longer behave the same. - Always run your test suite and PHPCS against the 8.0 ruleset before upgrading.
Overall PHP 8 makes code shorter and safer — well worth the upgrade once your dependencies are ready.
