Exciting News: PHP 8.2 Now Available on WordPress.com!

We are thrilled to announce that PHP 8.2 is now available on WordPress.com, bringing along a host of improvements and changes. While it quietly made its entrance yesterday, our developers couldn’t resist sharing the good news and highlighting some notable changes that will impact WordPress users and developers alike.

Notable Changes in PHP 8.2: Deprecated Dynamic Properties

For WordPress developers, one of the most significant changes in PHP 8.2 is the deprecation of dynamic properties. Traditionally, when writing a property that hasn’t been declared, PHP silently creates a dynamic property. This behavior is commonly used in WordPress plugins and themes to store data in objects. However, starting from PHP 8.2, this practice is deprecated and will be entirely removed in PHP 9.

// Given a Post class with one declared property...
class Post {
    public $post_title;
}
$post = new Post;

// Assigning declared property Post::$post_title is fine.
$post->post_title = 'PHP 8.2 Is Available On WordPress.com';

// Assigning an undeclared property raises deprecation warning.
$post->post_status = 'publish';
// PHP <= 8.1: Silently creates dynamic $post->post_status property.
// PHP 8.2: Raises deprecation warning, still creates dynamic property.
// PHP 9.0: Throws Error exception.

Two additional notable deprecations in PHP 8.2 include the deprecation of two forms of ${} string interpolation (braces after the dollar sign and variable variables) and the deprecation of the utf8_encode() and utf8_decode() functions, with mb_convert_encoding() recommended as the primary replacement.

For a comprehensive overview of all changes, including readonly classes and constants in traits, refer to the RFCs associated with PHP 8.2.

Upgrade Considerations and PHP 8 Features:

If you’re still on PHP 7.4, consider the notable features introduced in PHP 8, such as Just-in-Time (JIT) compilation. JIT allows PHP to compile code at runtime, resulting in improved performance and reduced memory usage. This is particularly beneficial for WordPress sites with complex plugins and themes.

How to Use PHP 8.2 on WordPress.com:

For WordPress.com Business and Ecommerce sites with hosting features activated, PHP version selection is now at your fingertips. To switch to PHP 8.2:

  1. Visit the Settings → Hosting Configuration section of your site’s dashboard.
  2. In the Web Server Settings section, view the current PHP version your site is running.
  3. Click the drop-down to select the PHP 8.2 version for your site.
  4. An “Update PHP Version” button will appear; click it to confirm your changes.

We strongly advise testing any new PHP version in a separate environment before implementing changes on your live site. For those comfortable with the command line, the PHPCompatibility for PHP CodeSniffer is a valuable tool for identifying code that may need adjustments.

Feel free to explore more about switching PHP versions on WordPress.com in our support portal, and share your thoughts on your favorite PHP 8.2 features in the comments below. Happy coding!