|
|
Subscribe / Log in / New account

First PHP 8 alpha released

By John Coggeshall
June 30, 2020

The PHP project has released the first alpha of PHP 8, which is slated for general availability in November 2020. This initial test release includes many new features such as just-in-time (JIT) compilation, new constructs like Attributes, and more. One of twelve planned releases before the general availability release, it represents a feature set that is still subject to change.

The PHP 8 release is being managed by contributors Sara Golemon and Gabriel Caruso. Dubbed "Alpha 1", this first release of PHP 8 is one of three releases to be done prior to a feature freeze. During this time, more widespread testing of new features is performed by the community and implementation details are worked out. This process will continue until August 4, at which point the feature set will be frozen to coincide with the first beta release scheduled for August 6.

Some interesting features

The release announcement omitted any specifics on new features or other changes, which would typically accompany a release. For now, the proposals that have been approved and implemented in the Request for Comments section of the PHP wiki is the best source of what is in the release now, and what might still be on the way.

Major-version PHP releases always have at least one significant improvement, and in this case, that is JIT for PHP 8. JIT will enable the engine to compile PHP code — a single PHP function or an entire application — to machine code for better performance. The RFC on the implementation provides a significant amount of detail regarding the JIT implementation for interested readers.

Beyond major improvements like JIT, there are also other new language-level features including Attributes. For those who are unaware, Attributes offer structured syntactic metadata for declarations in PHP code such as classes, functions, methods, and properties. Similar features already exist in other popular languages, such as annotations in Java and decorators in Python. Attributes replace the widely used phpDocumentor syntax for documentation block comments that is often deployed in PHP applications to serve a similar need. Currently in PHP 7, these comments are parsed at run time using PHP's reflection API to extract metadata.

One example of the existing use of this approach is the popular unit-testing framework PHPUnit, which uses documentation block annotations to implement things like order of operations in testing methods. With PHP 8, these same annotations can be defined and formalized into the language itself, eliminating the need for the expensive run-time comment parsing currently required. Attributes also may play a role in defining (or excluding) targets of PHP 8's new JIT compiler. Note that the Attributes feature is still in flux, with significant changes to the behavior still being decided and implemented before the August feature-freeze deadline.

PHP 8 will also support some desirable new language features for typing, continuing the trend of building robust data-type handling into the traditionally dynamically-typed language. Looking at current PHP 7 releases, there is support for typing in function/method declarations. However, this support is limited to two options: either a single data type is specified as part of the declaration, or no data type is specified at all. If no data type is specified, it is up to the developer to implement their own type-checking logic on an otherwise typeless value. This is less than ideal, as sometimes a method could reasonably be written that is given an integer or floating point number, but not a string. Like annotations, currently PHP projects handle this dilemma with documentation block comments that are intended to specify variable type details — but those details are not enforceable by PHP itself. To address this shortcoming, PHP 8 now supports type unions in declarations as part of its syntax, allowing developers to specify multiple types for functions, methods, and properties:

    class Number {
        private int|float $number;

        public function setNumber(int|float $number) : void
        {
            $this->number = $number;
        }

        public function getNumber() : int|float
        {
            return $this->number;
        }
    }

In the preceding example, the | operator is used to define multiple potential data types PHP will accept. In this case, an int or a float in the various contexts of the example. These checks are largely performed at runtime, although compile-time checks are also used to catch some cases.

Other changes expected in PHP 8 and implemented in Alpha 1 are the unbundling of legacy extensions like xmlrpc, previously rejected features like catching exceptions without requiring a variable for them, and the new Stringable interface to better handle __toString() implementations consistently in an application. In PHP, __toString() is a "magic method" of an object that, when provided, is used to return a string representation of an object. The Stringable interface provides a type that either accepts a primitive string data-type, or an object implementing the __toString() method for use in type-hinting.

More to come

This is only the first public release of the upcoming PHP 8 code base. As PHP 8 releases head toward general availability, future articles will follow the progress. The next release, Alpha 2, is scheduled for July 9. There are still many different discussions happening regarding features that may make it into the PHP 8.0 release, depending on whether they can be finalized in time for the feature-freeze deadline. In the meantime, early adopters can begin testing their code bases and reporting any bugs they might find.



to post comments

First PHP 8 alpha released

Posted Jun 30, 2020 20:24 UTC (Tue) by Sesse (subscriber, #53779) [Link] (5 responses)

The JIT looks awful; extremely simplistic bytecode-to-asm with nearly no type inference. Is this really worth it? Is it a good design to iterate on and build a faster JIT from? What are the real-world speedups for e.g. Wordpress, if an ideal case such as Mandelbrot only yields 4x?

First PHP 8 alpha released

Posted Jun 30, 2020 20:28 UTC (Tue) by Sesse (subscriber, #53779) [Link]

To answer my own question: A bit further down on the page, they have Wordpress numbers. It improves a meager 3.5% (they give no error bars).

First PHP 8 alpha released

Posted Jul 1, 2020 7:34 UTC (Wed) by flussence (guest, #85566) [Link]

A JIT isn't just for existing code; it changes the performance equation for code that would once have been unthinkable to write. This plus PHP7's FFI makes a transition away from hard-to-maintain PECL plugins more viable.

First PHP 8 alpha released

Posted Jul 1, 2020 11:32 UTC (Wed) by epa (subscriber, #39769) [Link] (2 responses)

It would be interesting to see a comparison between this effort and the JIT compiler for PHP developed by Facebook (which has now evolved into its own PHP dialect called Hack).

First PHP 8 alpha released

Posted Jul 1, 2020 11:41 UTC (Wed) by Sesse (subscriber, #53779) [Link]

Random searching found a test that indicates that four years ago, HHVM was 30% faster than PHP 7 on Wordpress. And PHP 8's JIT is (according to the authors) 3.5% faster than PHP 7.3 on Wordpress. YMMV.

https://www.wpoven.com/blog/hhvm-vs-php-7-performance-sho...

First PHP 8 alpha released

Posted Jul 1, 2020 12:34 UTC (Wed) by DG (subscriber, #16978) [Link]

Not JIT based, but for comparison of HHVM with PHP there's
https://kinsta.com/blog/hhvm-wordpress/ - see about 1/3 of the way down which seems to show PHP 7.2 is faster than HHVM (at least for Wordpress)

https://hhvm.com/blog/2018/09/12/end-of-php-support-futur... - HHVM dropping support for PHP - so any comparison is going to be difficult.


Copyright © 2020, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds