PHP 7: Maintaining and Upgrading Legacy Apps · PHP 7 Language Essentials
What PHP 7 Changed
The PHP 7 engine, scalar and return types, and the Throwable hierarchy.
PHP 7.0 (2015) replaced the Zend Engine with PHPNG, roughly doubling performance and cutting memory use versus PHP 5.6. It added scalar type declarations (int, float, string, bool), return types, declare(strict_types=1), the ?? and <=> operators, anonymous classes, and turned most fatal errors into catchable Error exceptions under the new Throwable interface. Old mysql_* functions and ASP-style tags were removed.
All PHP 7 branches are end-of-life (7.4 ended in November 2022), so PHP 7 work today is mostly maintaining and upgrading legacy applications.
<?php
declare(strict_types=1);
function average(array $values): float
{
if (count($values) === 0) {
throw new InvalidArgumentException('Empty list');
}
return array_sum($values) / count($values);
}
try {
undefined_function();
} catch (Error $e) { // PHP 7: engine errors are catchable
error_log($e->getMessage());
}
Common pitfalls
- Catching
Exceptionand assuming it covers engine errors —Erroris a separate branch ofThrowable. - Assuming PHP 7 code is still supported — no PHP 7 version receives security fixes from php.net.
- Mixing strict and coercive typing across files without realizing the setting is per file.
Key points
- PHP 7 brought a huge performance jump
- Scalar/return types and Throwable arrived in 7.0
- All PHP 7.x versions are end-of-life
Further reading: PHP manual: PHP 7.0 new features
Practice questions
How does error handling differ between PHP 5 and PHP 7?
Answer
In PHP 7 many fatal errors became Error exceptions (implementing Throwable) that can be caught. catch (Exception $e) doesn't catch them; use catch (Throwable $t) at top-level handlers.
Why is running PHP 7.4 in production a risk today?
Answer
It reached end-of-life in November 2022 and no longer gets official security fixes, so new vulnerabilities stay unpatched unless you use a paid extended-support vendor.
Open in the app to mark lessons complete, take notes and track your progress.