During 2014 and 2015, a new major PHP version was developed, which was numbered PHP 7. The numbering of this version involved some debate. While the PHP 6 Unicode experiment had never been released, several articles and book titles referenced the PHP 6 name, which might have caused confusion if a new release were to reuse the name. After a vote, the name PHP 7 was chosen.
The foundation of PHP 7 is a PHP branch that was originally dubbed PHP next generation (phpng). It was authored by Dmitry Stogov, Xinchen Hui and Nikita Popov, and aimed to optimize PHP performance by refactoring the Zend Engine while retaining near-complete language compatibility. As of 14 July 2014, WordPress-based benchmarks, which served as the main benchmark suite for the phpng project, showed an almost 100% increase in performance. Changes from phpng are also expected to make it easier to improve performance in the future, as more compact data structures and other changes are seen as better suited for a successful migration to a just-in-time (JIT) compiler. Because of the significant changes, the reworked Zend Engine is called Zend Engine 3, succeeding Zend Engine 2 used in PHP 5.
Because of major internal changes in phpng it must receive a new major version number of PHP, rather than a minor PHP 5 release, according to PHP's release process. Major versions of PHP are allowed to break backward-compatibility of code and therefore PHP 7 presented an opportunity for other improvements beyond phpng that require backward-compatibility breaks. In particular, it involved the following changes:
- Many fatal- or recoverable-level legacy PHP error mechanisms were replaced with modern object-oriented exceptions
- The syntax for variable dereferencing was reworked to be internally more consistent and complete, allowing the use of the operators
::, with arbitrary meaningful left-side expressions
- Support for legacy PHP 4-style constructor methods was deprecated
- The behavior of the
foreachstatement was changed to be more predictable
- Constructors for the few classes built-in to PHP which returned null upon failure were changed to throw an exception instead, for consistency
- Several unmaintained or deprecated server application programming interfaces (SAPIs) and extensions were removed from the PHP core, most notably the legacy
- The behavior of the
list()operator was changed to remove support for strings
- Support was removed for legacy ASP-style delimiters
<script language="php"> ... </script>
- An oversight allowing a switch statement to have multiple
defaultclauses was fixed
- Support for hexadecimal number support in some implicit conversions from strings to number types was removed
- The left-shift and right-shift operators were changed to behave more consistently across platforms
- Conversions between integers and floating point numbers were tightened and implemented more consistently across platforms
PHP 7 also included new language features. Most notably, it introduces return type declarations for functions which complement the existing parameter type declarations, and support for the scalar types (integer, float, string, and boolean) in parameter and return type declarations.
Friday, July 12, 2019