PHP 8: JIT, attributes, match and named arguments

Contents
Introduction
match instead of switch
Calls that read like config
Stricter, with less writing
JIT: measure before celebrating
Deep dives on this site

Introduction

PHP 8 (2020) changes how code reads more than any release since 5: expressions replace statements, calls name their arguments, and metadata moves from doc-comments into the engine. The one-line tour below; full detail in the deep dives at the end.

Author: Arthur Isaev

match instead of switch

match is an expression with strict comparison and no fall-through — an unhandled value throws instead of silently doing nothing:

<?php namespace Aredel\Demo; $label = match ($status) { 200, 201 => 'ok', 404 => 'missing', default => 'error', }; echo $label;

Calls that read like config

Named arguments (start_index: 0) end boolean-flag guessing at call sites; attributes (#[Route(...)]) replace doc-comment annotations with reflection-readable syntax.

Stricter, with less writing

Union types (int|float), constructor promotion (declare and assign the property in the signature — see OOP in PHP), nullsafe operator (?->), and throw as an expression.

JIT: measure before celebrating

The tracing JIT speeds CPU-heavy code (parsers, serializers, math); typical web requests gain little. Enable OPcache first, measure, then experiment — same advice as every version.

Deep dives on this site

What is new in PHP 8.0 vs PHP 7 — every feature above with examples.

What is new in PHP 8.5 vs PHP 8.0 — the other end of the 8.x line.

Article author: Arthur Isaev

Related articles
Development with PHP
PHP versions: history in brief
PHP 5: the release that made PHP object-oriented
PHP 7: twice as fast, with scalar types
PHP 8: JIT, attributes, match and named arguments
What is new in PHP 8.0 vs PHP 7
What is new in PHP 8.5 vs PHP 8.0

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: