BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News PHP 8 Brings New JIT, Union Types, and More

PHP 8 Brings New JIT, Union Types, and More

This item in japanese

Bookmarks

PHP 8 is a major update to PHP that includes a new just in time compiler (JIT) and many new language features. InfoQ has spoken with Sentry principal developer Mark Story better understand what role PHP and PHP 8 play in today's language landscape.

Undoubtedly one of the most awaited feature, the PHP JIT is aimed to improve PHP performance by generating native code from PHP bytecode using DynASM (Dynamic Assembler for code generation engines). The PHP JIT will make PHP 8 much faster than previous versions executing CPU-intensive code but this will not necessarily translate into improved performance of real-life application such as Wordpress and others, where additional factors including network performance, database access, etc. play a critical role.

On the language front, PHP 8 includes many new features meant to improve the type system and make the language more "modern". Those includes the possibility of using union types in function signatures; a new match expression that can replace switch with safer semantics; saner string to number comparisons aimed to remove a frequent cause of bugs and unexpected behaviour; named arguments, which enable passing arguments to functions by names instead of positionally; weak maps to enable creating maps without retaining its objects, and much more.

InfoQ has taken the chance to speak to Mark Story, principal developer at application monitoring company Sentry to better understand what role PHP and PHP 8 play in today's language landscape.

InfoQ: Why should anyone still use PHP 8 in 2020 in your opinion?

Story: PHP continues to be a great choice for web applications and API servers. The ability to get started quickly and leverage powerful, mature frameworks and libraries to quickly deliver products is a continued strength of PHP. Later, as a team needs to grow, the PHP talent pool is deep and finding developers that are experienced with PHP is easier than with newer or more exotic platforms.

Another reason I would consider PHP in 2020 is the continued evolution and performance improvements that the PHP team has been delivering through the 7.x release series. Each release of PHP continues to incrementally improve the “bad parts” of PHP while also improving performance, ease of use and type safety features. PHP is a battle tested technology that underpinned a number of very successful companies. Companies like Facebook, Etsy, and Slack, and projects like Wikipedia were all built in PHP.

InfoQ: How does PHP compare to more "modern" programming languages for Web development?

Story: In many ways PHP has helped set the bar for what a “modern” server environment should look like. Other platforms go to great lengths to deliver the “shared nothing” architecture that PHP has built-in. PHP offers best-in-class horizontal scalability. Due to its lack of threading, and shared memory, PHP helps you make good choices that set you up for being able to scale horizontally. When you need to handle additional traffic, more web servers can be added to your fleet.

When comparing PHP to other languages, it is important to compare it to other dynamic interpreted languages. Compiled languages like Go or Rust will perform significantly better than PHP can. The trade-off with compiled languages is that they are often slower to get started and build new functionality in.

InfoQ: What are in your opinion the most compelling new features in PHP 8?

Story: For me the addition of named parameters and other ergonomic improvements like null-safe operator and match expression is the biggest wins in PHP 8. While I’m a fan of union types as they move PHP closer to having a more complete type system, the ergonomic improvements will help improve readability of code and make PHP easier to use. Named parameters are inspired by Python’s keyword arguments or “kwargs” and let you define only the parameters that are required or need a non-default value. Because the parameter names are also part of how a function is called, code is easier to read. You no longer have to look up what the fifth parameter to “setcookie()” is. Instead you only need to remember the parameter names and what their values need to be.

The match expression and null-safe operators borrow from Rust and JavaScript and make commonly used patterns easier to implement as they enable more expressive code.

InfoQ: What would you have liked to see in PHP 8?

Story: I would have loved to see intersection types in addition to union types. Having both would have enabled static analyzers and the PHP runtime to ensure even more type safety.

PHP 8 also includes changes that break backward-compatibility and this might bite developers more or less depending on the cleanness of their codebases.

If you are interested in the full detail about this new PHP release do not miss its official announcement.

Rate this Article

Adoption
Style

BT