8.0.30

Latest release in branch 8.0
Released 2 years ago (August 03, 2023)

Software PHP
Branch 8.0
Status
End of life
End of bug fixes November 26, 2022
End of security fixes November 26, 2023
First official release version 8.0.0
First official release date 5 years ago (November 26, 2020)
Release notes https://www.php.net/ChangeLog-8.php#8.0.30
Source code https://github.com/php/php-src/tree/php-8.0.30
Documentation https://www.php.net/manual/en/
Download https://www.php.net/releases/8.0.30
PHP 8.0 Releases View full list

What Is New in PHP 8.0

PHP 8.0 is a major update that introduces the JIT compiler, new language features like attributes and union types, and several improvements and deprecations.

Category Key Changes
New Features JIT Compiler, Attributes, Union Types, Match Expression, Constructor Property Promotion, throw Expression, Nullsafe Operator
Improvements Type System Enhancements (mixed type), Stringable interface, WeakMap class, Trailing comma in parameter lists
Deprecations & Changes Deprecations of several functions and features, changes to error reporting and standard library functions

How does the JIT compiler improve performance?

The Just-In-Time (JIT) compiler is the flagship feature of PHP 8.0. It translates parts of the PHP opcode into machine code at runtime, which can then be executed directly by the CPU.

In practice, this provides significant performance benefits for long-running applications, especially in mathematical computations and large-scale applications. For typical web requests, the difference might be less dramatic but still positive.

It's enabled in the php.ini file and offers different tracing modes to suit various workloads.

What new syntax features should I start using?

Attributes

Attributes allow you to add structured metadata to classes, methods, properties, and more. They replace the docblock comments used by many frameworks for annotations.

<?php
#[Route("/api/posts", methods: ["GET"])]
class PostController
{
}
?>

Union Types

You can now declare that a parameter, property, or return value can be of multiple types. This makes the type system much more expressive.

public function foo(string|int $bar): string|int|null

Match Expression

The match expression is a more powerful and safer alternative to the switch statement. It returns a value, does strict comparisons, and requires exhaustive matching.

$result = match ($statusCode) {
    200, 300 => 'OK',
    404 => 'Not Found',
    default => 'Unknown',
};

Nullsafe Operator

The nullsafe operator (?->) short-circuits method or property access if the object is null, preventing the need for nested null checks.

$country = $session?->user?->getAddress()?->country;

What breaking changes might break my existing code?

PHP 8.0 includes several changes that are not backward compatible. The most common issues arise from stricter type checking and promoted error levels.

  • Stricter Type Checks: Parameters with union types and the new mixed type enforce stricter rules.
  • Error to Exception Conversions: Many fatal errors are now converted into Error exceptions, which can change how your application handles failures.
  • Standard Library Changes: Functions like str_contains() are now case-sensitive, and some parameters have been swapped for consistency.
  • Deprecations: Functions and features that were deprecated in PHP 7.x have now been removed.

Running your code with error reporting set to E_ALL is the best way to identify these issues before upgrading.

FAQ

Is the JIT compiler enabled by default?
Yes, the JIT is enabled by default in PHP 8.0, but it is configured with a buffer size of 0, effectively turning it off. You need to configure the opcache.jit_buffer_size directive in your php.ini to a non-zero value to activate it.

What is the difference between the new 'match' and a 'switch' statement?
match is an expression that returns a value, uses strict type comparisons (===), and does not require a break. It also throws an UnhandledMatchError if no arm is matched, unless a default case is provided.

How do Union Types work with inheritance?
A child class can widen the return type of a method using a union that includes the parent's return type. However, it can only narrow parameter types, not widen them, to comply with the Liskov Substitution Principle.

What replaces the old @annotations in docblocks?
You should use native PHP Attributes instead. They are declared with #[ ] syntax and are first-class citizens in the language, making them more efficient and easier to parse than docblock comments.

Why did they change the parameter order for some functions?
Functions like implode() now have a consistent parameter order. The $glue and $pieces parameters for implode() can be passed in either order for backward compatibility, but the documented order is now consistent with other functions.

Releases In Branch 8.0

Version Release date
8.0.30 2 years ago
(August 03, 2023)
8.0.29 2 years ago
(June 08, 2023)
8.0.28 3 years ago
(February 14, 2023)
8.0.27 3 years ago
(January 05, 2023)
8.0.26 3 years ago
(November 24, 2022)
8.0.25 3 years ago
(October 27, 2022)
8.0.24 3 years ago
(September 29, 2022)
8.0.23 3 years ago
(September 01, 2022)
8.0.22 3 years ago
(August 04, 2022)
8.0.21 3 years ago
(July 07, 2022)
8.0.20 3 years ago
(June 09, 2022)
8.0.19 3 years ago
(May 12, 2022)
8.0.18 4 years ago
(April 14, 2022)
8.0.17 4 years ago
(March 17, 2022)
8.0.16 4 years ago
(February 17, 2022)
8.0.15 4 years ago
(January 20, 2022)
8.0.14 4 years ago
(December 16, 2021)
8.0.13 4 years ago
(November 18, 2021)
8.0.12 4 years ago
(October 21, 2021)
8.0.11 4 years ago
(September 23, 2021)
8.0.10 4 years ago
(August 26, 2021)
8.0.9 4 years ago
(July 29, 2021)
8.0.8 4 years ago
(July 01, 2021)
8.0.7 4 years ago
(June 03, 2021)
8.0.6 4 years ago
(May 06, 2021)
8.0.5 4 years ago
(April 29, 2021)
8.0.3 5 years ago
(March 04, 2021)
8.0.2 5 years ago
(February 04, 2021)
8.0.1 5 years ago
(January 07, 2021)
8.0.0 5 years ago
(November 26, 2020)