« Previous 1 2 3 4
New features in PHP 8
Conversion Work
Stricter Reporting Requirements
If you call existing scripts in PHP 8, you can expect numerous error messages. Besides some incompatible changes, the main reason for these errors is stricter handling. From now on, the error report level E_ALL
will be used by default. Additionally, the @
operator can be used to suppress fatal errors. Developers must also be prepared for SQL errors when connecting to databases via the PDO interface: Error handling now uses exception mode by default (PDO::ERRMODE_EXCEPTION
).
Arithmetic and bitwise operators throw a TypeError
if one of the operands is an array, a resource, or not an overloaded object. One exception occurs if you merge two arrays using array + array
. Division by zero throws a DivisionByZeroError
in PHP 8.
Finally, PHP 8 removes some functions and language constructs already tagged as deprecated
in version 7.x. The PHP developers meticulously list all incompatible changes in a long document online [5]. If you need to maintain existing PHP code, you will definitely want to check out this document.
Conclusions
PHP 8 includes many useful new features that make the developer's life easier and provide for more compact code. In particular, the new match
, Constructor Property Promotion, and attributes should quickly find many friends. In addition, PHP 8 cautiously throws out some outdated behaviors and constructs. Existing PHP applications, however, will most likely need to be adapted as a result. Whether the JIT compiler really delivers the hoped-for performance boost or only gives PHP code a boost in special cases remains to be seen in practice.
Infos
- OPcache: https://www.php.net/manual/en/book.opcache.php
- "PHP 8: JIT performance in real-life web applications": https://stitcher.io/blog/jit-in-real-life-web-applications
- token_get_all: https://www.php.net/manual/function.token-get-all.php
- Traits: https://www.php.net/manual/language.oop5.traits.php
- Upgrading to PHP 8.0: https://github.com/php/php-src/blob/master/UPGRADING
« Previous 1 2 3 4
Buy this article as PDF
(incl. VAT)