By John Spellman February 21, 2023
PHP 8.2 was released on December 8, 2022 and is now available on Pantheon. You can update with confidence using Pantheon’s Dev, Test, Live workflow because the PHP version is managed in version control and deployed along with the rest of your code.
We suggest using the latest PHP version to maximize your site’s security, as well as getting syntax and execution upgrades. Additionally, each PHP point release includes changes that remove ambiguity.
Back when WordPress and Drupal were first introduced, PHP did little at the language level to discourage confusing practices, such as functions that accept and return different types of data. In the years since then, through a combination of education from the community and re-working at the language-level, it has become easier to write unambiguous code using PHP.
Dynamic properties are depreciated
While there are a number of low-level changes in 8.2 (that are unlikely to change your regular work), there is one depreciation that jumps out. For Drupal and WordPress developers, the depreciation of dynamic properties is the most notable change in PHP 8.2. This is a significant backwards compatibility break, and many folks will need to revisit older code to fix this depreciation notice. The depreciation notice will become an Error exception in PHP 9.0.
The problem here is that it can be confusing if you see a property (bar) getting set on an object, when the original declaration of the class never mentioned anything about "bar." If you're going to set and use a property on an object, you should first tell the computer, and, perhaps, more importantly your human co-workers, what that property means.
Fixing depreciation warningsAdding properties to objects dynamically isn't the end of the world. It's just a pattern of poor code hygiene that can be eliminated at the language level. But fixing the code in any given site or package might be time consuming or even risky. So there's a band-aid solution available to suppress the depreciation notices.
Any classes declared with the #[AllowDynamicProperties] attribute will not emit a depreciation notice in 8.2. For example, WordPress has already begun to address this depreciation in Core, making use of #[AllowDynamicProperties]:
The better fix would be to add the property declaration to the class:
For more details regarding this depreciation, check out the RFC.
Interested in Upgrading?
Pantheon customers are able to make the update to PHP 8.2 by following our documentation on how to upgrade your PHP version.
It’s worth noting that New Relic is not yet supported in PHP 8.2, but we hope to see a release with support in the near future. We’re keeping an eye on this GitHub issue for updates, and will test out a release when one becomes available.
If you still have questions, please reach out to support for help