PHP 8.2 is Now Available on WordPress.com

We’re excited to announce PHP 8.2 availability on WordPress.com!

In fact, it was actually available yesterday, but you know how much developers like writing blog posts…

Notable Changes in PHP 8.2

For WordPress developers, deprecated dynamic properties is probably the most significant change in PHP 8.2.

Historically, when writing a property that hasn’t been declared, PHP silently creates a dynamic property instead. Objects can be a useful place to store data, so use of dynamic properties is quite common in WordPress plugins and themes. However, this behavior is deprecated in PHP 8.2, and will be 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 is changing.
$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 other notable deprecations in PHP 8.2 include:

Check out the RFCs for the full breadth of changes in PHP 8.2, including readonly classes and constants in traits.

If you haven’t upgraded from PHP 7.4 just yet, one of the most notable features in PHP 8 is the addition of JIT (Just-in-Time) compilation. This allows PHP to compile code at runtime, rather than before execution, resulting in faster performance and reduced memory usage. This can greatly improve the speed of WordPress sites, especially those with complex plugins and themes.

Use PHP 8.2 on WordPress.com

PHP version selection is available to all WordPress.com Business and Ecommerce sites with hosting features activated.

We strongly encourage you to test any new PHP version in another environment before changing it on your live site. If you’re comfortable with the command line, the PHPCompatibility for PHP CodeSniffer is a helpful tool for identifying some code that needs to change (it doesn’t quite find everything, yet).

To switch the PHP version for your site:

  1. Visit the Settings → Hosting Configuration section of your site’s dashboard. 
  2. In the Web Server Settings section, you can see the version of PHP your site is currently running.
  3. Click the drop-down to change the version your site runs.
  4. An Update PHP Version button will appear. Click the button to confirm your changes.
Image showing where to switch the PHP version for your site under Web Server Settings.

Learn more about switching PHP versions on WordPress.com in our support portal, or let us know your favorite PHP 8.2 feature in the comments.