PHP 8.0 adds metadata to classes
There is a major new version of PHP with improvements including a nullsafe operator and attributes allowing the use of structured metadata with native PHP syntax.
PHP started 25 years ago as a simple scripting language designed for building web pages, but it has grown into a general server-side web language. It is now used for eight out of ten websites using server-side code.
This is a major language upgrade, with a number of notable improvements. Support for metadata for classes via attributes provides an alternative to the previous technique of parsing docblocks. Attributes are commonly referred to as annotations in other languages.
There are two new JIT compilers in the new version. JIT Tracing, which the developers say is the more promising of the two, performs roughly three times better on synthetic benchmarks and up to twice as good on some specific long-running applications.
The developers say they decided to include the JIT compilers because they no longer have other ways to improve PHP performance using other optimization strategies. They also believe that using JIT may open the door to more frequent use of PHP in other non-web, CPU-intensive scenarios where PHP was not considered a language without JIT.
The addition will also provide the ability to develop built-in functions in PHP, in place of (or in addition to) C – without incurring the huge performance penalty that would be associated with such a strategy in the previous, non-JITted engine.
Another improvement is the new nullsafe operator. This means that developers can avoid issues with the null coalescing operator, especially that it does not work on method calls. The new operator means that PHP behaves like zero coalescing on methods.
Other improvements include the addition of Union types, collections of two or more types that indicate that either can be used; and named arguments, so you can now pass arguments to a function based on the name of the parameter rather than the position of the parameter.
PHP 8.0 is now available for download.
PHP 7.4 gets a foreign function interface
PHP is the best?
PHP 7.2 with integrated Libsodium
What PHP does
PHP Variables and Expressions for Complete Beginners
Object oriented HTML generation in PHP
PHP 5.6 released
PHP gets a formal specification
To be informed of new articles on I Programmer, subscribe to our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
or send your comment to: [email protected]