PHP 8: JIT, attributes, match and named arguments

Содержание
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.

Автор статьи: Андрей Олегович

Похожие статьи
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

Поиск по сайту

Канал @aofeed Чат @aofeedchat

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящую по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: