---
title: "PHP 8: JIT compiler and union types"
description: "PHP 8.0 introduces a DynASM-based JIT compiler, union types, named arguments, match expression and attributes. After twenty-five years, PHP evolves with a gradual type system."
url: "https://www.noze.it/en/insights/php8-open-source/"
lang: "en"
alternate: "https://www.noze.it/insights/php8-open-source/"
published: "2020-12-15"
author: "noze S.r.l."
keywords: "Open Source, Web, PHP, JIT, Type System, Backend"
---

# PHP 8: JIT compiler and union types

PHP 8.0 introduces a DynASM-based JIT compiler, union types, named arguments, match expression and attributes. After twenty-five years, PHP evolves with a gradual type system.

15 December 2020

## Twenty-five years of evolution

[**PHP 8.0**](https://www.php.net), released in November 2020, represents the most significant generational leap for the language since the introduction of the object model in PHP 5. After twenty-five years from its first version, PHP remains the most widely used server-side language on the web — it powers the majority of sites built on **WordPress**, **Drupal**, **Magento** and dozens of other CMS platforms and frameworks — but its recent evolution points in a different direction: native performance and an increasingly rigorous type system.

## The JIT compiler

The most anticipated feature is the **JIT compiler** (Just-In-Time), based on **DynASM**, the machine code generation framework also used by **LuaJIT**. The JIT compiles PHP bytecode into native machine code at runtime, eliminating the repeated interpretation of the most frequent instructions.

The impact on traditional web applications — where the bottleneck is typically I/O to databases and network — is modest. The JIT shines in **CPU-intensive workloads**: mathematical calculations, image processing, parsing algorithms. For these scenarios the performance gain is significant, bringing PHP closer to the performance of compiled languages.

The JIT operates in two modes: **tracing**, which analyses the most frequent execution paths, and **function**, which compiles entire functions. Tracing mode generally offers better performance but with an initial profiling overhead.

## Union types and the gradual type system

**Union types** allow declaring that a parameter or return value accepts multiple types: `int|string` is now a valid declaration. This feature fills a historic gap: PHP has always handled multiple types implicitly through type juggling, but without being able to express it in the formal type system. With union types, code documents its intentions and static analysis tools can verify them.

## Named arguments and match expression

**Named arguments** allow passing parameters by name rather than position: `htmlspecialchars(string: $text, double_encode: false)`. Readability improves especially in functions with many optional parameters, a common pattern in PHP APIs.

The **match expression** is a pattern matching construct that replaces the most common use cases of `switch`: strict comparison, no fall-through, evaluation as an expression. Code becomes more compact and less prone to logical errors.

## Attributes and breaking changes

**Attributes** (native annotations) replace structured PHPDoc comments with formal language syntax: `#[Route("/api/users")]`. The runtime can read attributes via reflection, enabling frameworks and libraries to use declarative metadata without external parsers.

PHP 8.0 also introduces several **breaking changes**: removal of deprecated functions, strict-by-default behaviour for string-to-number comparisons, errors where previously there were warnings. These breaks, managed through migration tools and detailed guides, clean up inconsistencies accumulated over decades of backward compatibility.

**Link**: [php.net](https://www.php.net)
