PHP 8.2 Available on WordPress VIP

We are excited to announce the availability of PHP 8.2 on WordPress VIP. This version introduces a host of new features, improvements, and deprecations. Here are some of the key highlights.

New features

Readonly Classes: PHP 8.2 introduces the concept of readonly classes. This allows you to define classes where certain properties are read-only and cannot be changed after they are set in the constructor.

Disjunctive Normal Form (DNF) Types: DNF types allow us to combine union and intersection types, following a strict rule: when combining union and intersection types, intersection types must be grouped with brackets.

Allow null, false, and true as stand-alone types: In PHP 8.2, null, false, and true can be used as stand-alone types. This allows for more precise type declarations in your code.

New “Random” extension: The “random” extension provides a new object-oriented API to random number generation. Instead of relying on a globally seeded random number generator (RNG) using the Mersenne Twister algorithm, the object-oriented API provides several classes (“Engine”s) providing access to modern algorithms that store their state within objects to allow for multiple independent seedable sequences.

Constants in traits: PHP 8.2 allows you to define constants in traits. However, you cannot access the constant through the name of the trait, but, you can access the constant through the class that uses the trait.

Deprecations and backward incompatible changes

  • Deprecated dynamic properties: The creation of dynamic properties is deprecated, unless the class opts in by using the #[\AllowDynamicProperties] attribute. stdClass allows dynamic properties. Usage of the __get()/__set() magic methods is not affected by this change. 
  • Deprecated ${} string style interpolation
  • Deprecated utf8_encode and utf8_decode functions.

Additional information about deprecations and the full list of backward incompatible changes can be reviewed on the PHP.net website.

More detailed information about all of the changes in PHP 8.2 is available in the official PHP 8.2 release notes.

Testing your application with PHP 8.2

It’s always a good idea to test your application code with every new release of PHP.

WordPress VIP recommends that you use several methods to prepare for a PHP upgrade.

Scan your codebase for incompatibilities

Review the WordPress VIP documentation “Prepare application code for a PHP version upgrade” guide and perform the scan.

Test with the VIP Local Development Environment

We recommend using the VIP Local Development Environment to test your application code locally.

Create a new environment with PHP 8.2: 

vip dev-env create --slug=mytestsite --php=8.2

Or update an existing local environment with PHP 8.2: 

vip dev-env update --slug=mytestsite --php=8.2
An example of VIP-CLI command to create a new environment

Test with a non-production VIP Platform environment

To update your non-production environments to PHP 8.2, either use the Software Management feature in the VIP Dashboard, or run the vip config software update command with VIP-CLI. For example:

vip @mytestsite.testing config software update php 8.2
Software Management - PHP screen
An example of CLI comand to update the local dev env