PHP 8.2 Available on All Servers

September 21, 2022

Today we’re excited to announce that the release candidate of PHP 8.2 is now available on all ServerPilot servers. There are many changes, new features, and notable deprecations with the release of PHP 8.2. Continue reading to learn more about what has changed in PHP 8.2.

PHP 8.2 Changes

Redacting parameters in backtraces

Stack traces provide an amount of verbosity which can allow sensitive information to be exposed whenever Exceptions occur. Applications often handle various kinds of sensitive information about an individual user and exposure from passing secrets into a function that could fail puts the user at risk. This information can also be passed to third-party log services, further risking security.

The \SensitiveParameter attribute is a new prevention measure that can be added to a function’s parameter designating it as secret and to be hidden from backtraces. Learn more.


function test(
    #[\SensitiveParameter] $bar,
) {
    throw new \Exception('Error');
test('foo', 'bar', 'baz');

Results in the following stack trace:

Fatal error: Uncaught Exception: Error in test.php:8
Stack trace:
#0 test.php(11): test('foo', Object(SensitiveParameterValue), 'baz')
#1 {main}
  thrown in test.php on line 8

Readonly classes

Support for readonly properties was introduced in PHP 8.1. That modifier is now available to classes. The readonly modifier will instantly mark all of the instance properties of a class as readonly. This is handy when there are a lot of properties. Usage of readonly also keeps dynamic properties from being created. Learn more.


readonly class Foo
    public int $bar;

    public function __construct() {
        $this->bar = 1;

$foo = new Foo();
$foo->bar = 2;
// Fatal Error: Uncaught Error: Cannot modify readonly property Foo::$bar

$foo->baz = 1;
// Fatal Error: Uncaught Error: Cannot create dynamic property Foo::$baz

Dynamic properties have been deprecated in PHP 8.2. Please see the deprecations below. There is now a #[AllowDynamicProperties] attribute that allows the creation of dynamic properties.

Use null and false as stand-alone types

With PHP 8.2, false and null can now be used as stand-alone types adding more completeness to the PHP type system. Learn more.

True type

There was no true type previously, so support for using true as a type declaration has been added. Learn more.

Disjunctive Normal Form (DNF) types

There is now support for disjunctive normal form types in PHP 8.2, which allows the mixing of union and intersection types that can be parsed. DNF is a standard way to organize boolean expressions using an ORed series of ANDs. Learn more.

error_log_mode setting permissions for error log file

PHP 8.2 added a new error_log_mode ini directive that allows the setting of error log file permissions.

Fetch properties of enums in const expressions

With PHP 8.2, it’s now possible to fetch properties of enums in constant expressions with ->/?->. Allows for the name and value properties to be fetched where enum objects are not allowed. Learn more.

Constants in Traits

Methods and properties allow for defining constants, while traits do not. Therefore, you cannot define constants expected by a trait within that trait. In PHP 8.2, you can now define constants in traits like you do for properties. Learn more.

trait Foo {
    public const FLAG_1 = 1;
    protected const FLAG_2 = 2;
    private const FLAG_3 = 2;

    public function doFoo(int $flags): void {
        if ($flags & self::FLAG_1) {
            echo 'Got flag 1';
        if ($flags & self::FLAG_2) {
            echo 'Got flag 2';
        if ($flags & self::FLAG_3) {
            echo 'Got flag 3';

New Functions

memory_reset_peak_usage() will reset the peak memory usage given by the memory_get_peak_usage() function.

curl_upkeep() adds connection upkeep checks to the Curl extension.

ini_parse_quantity() returns bytes for any data size recognized by php.ini because data size suffixes like 512M or 2G are not internationally standardized.

mysqli_execute_query() reduces the amount of code and complexity to create parameterized queries. Learn more.

openssl_cipher_key_length() returns the key length of provided cipher.

Changes and Deprecations

Deprecated creation of dynamic properties. Use the #[AllowDynamicProperties] attribute. Learn more.

Callables supported by call_user_func($callable), but not by $callable() (partially supported callables) are deprecated: Learn more.

["self", "method"]
["parent", "method"]
["static", "method"]
["Foo", "Bar::method"]
[new Foo, "Bar::method"]

The "${var}" and "${expr}" style string interpolations are deprecated and will be removed in PHP 9. Learn more.

QPrint, HTML-ENTITIES 'text encodings’, Uuencode, and Base64 are deprecated for all Mbstring functions.

The functions utf8_encode() and utf8_decode() are deprecated. Use mb_convert_encoding(). Learn more.

MySQLi support for libmysql was removed. Learn more. ODBC (and PDO_ODBC) extension will now escape the username and password when a connection string and username/password are passed.

How to Switch to PHP 8.2

You can change an app to use PHP 8.2 through your app's Settings in ServerPilot. If your app does not work with PHP 8.2, you can easily change back.

As always, please contact us if you have any questions.

PHP 8.2 is only available on servers with Ubuntu 16.04 and later.