PHP 7: twice as fast, with scalar types

Содержание
Introduction
Roughly twice as fast
Scalar and return types
?? and <=>
Engine errors you can catch
The rest of the 7.x line

Introduction

PHP 7 (2015) is two upgrades at once: the PHPNG engine roughly doubles real-world speed at same hardware, and the type system grows up — scalar declarations, return types, and engine errors you can finally catch. Most PHP 5 code runs faster untouched; new code gets stricter.

Author: Arthur Isaev

Roughly twice as fast

PHPNG (the new Zend Engine) halves request time and memory on typical CMS and framework workloads — the upgrade paid for itself on the hosting bill alone. No code changes required to collect most of it.

Scalar and return types

Parameters and returns finally declare int, string, bool, float — wrong types throw TypeError instead of silently coercing somewhere downstream:

<?php namespace Aredel\Demo; function headline(string $title): string { return '<h1>' . $title . '</h1>'; } $name = $_GET['name'] ?? 'guest'; echo headline($name);

?? and <=>

?? (null coalescing) collapses the isset() ternary into one operator; <=> (spaceship) returns -1, 0 or 1, so comparators stop hand-rolling sign logic:

<?php namespace Aredel\Demo; $byLength = function (string $a, string $b): int { return strlen($a) <=> strlen($b); };

Engine errors you can catch

Fatal engine errors (bad calls, type failures) become Error throwables catchable with try / catch — the guard pattern from require fallback works uniformly now. Plus: anonymous classes for one-off test doubles and handlers.

The rest of the 7.x line

7.1: nullable types, void returns, iterable. 7.2: Argon2 passwords, libsodium crypto. 7.3: flexible heredoc, trailing commas in calls. 7.4: arrow functions, typed properties, spread in arrays.

Next: PHP 8 — JIT, attributes, match and named arguments.

Article author: Arthur Isaev

Похожие статьи
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. Статьи можно расшарить в соцсетях, нажав на иконку сети: