PHP 7: twice as fast, with scalar types

Contents
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);

Banner image

?? 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

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, info@aredel.com 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: