How to upgrade
You can explore all that PHP 8.4 has to offer on your projects today.Install the new version
First, follow the official instructions for installing PHP 8.4 on your computer: Then you can check that it’s installed and accessible with:Create a new environment
Create a branch dedicated to the latest version:Upgrade your dependencies
Run the command:Upgrade your configuration
- Single runtime image
- Composable image
On Upsun:and on Platform.sh:
upsun push.
Once the environment is live, you can merge the upgrades now (upsun merge), then come back to visit many of the performance improvements and new features packaged in the release below.
You can test the changes on the new environment with an upsun push.
You can as always find more information about available extensions and PHP configuration in the Upsun and Platform.sh documentation.
A note on production upgrades:There are some noted incompatibilities that come with this new minor version release that you should keep in mind when upgrading production environments.
Consult those warnings and the links below for more details.
What’s changed in PHP 8.4?
With this release comes a number of resources to better understand what’s changed, and how those changes impact your applications:- A comprehensive list of all changes can be found in the ChangeLog
- A side-by-side comparison on the release homepage
- Migrating from PHP 8.3.x to PHP 8.4.x instructions, which further breaks down the changes into:
New features
While there are a great number of improvements, updates, and added functions and subclasses in this release, much of the discussion up to this point has seemed to focus primarily on three enhancements in particular.-
Property hooks
With much inspiration from Kotlin, Property hooks in PHP 8.4 allow for defining additional logic (such as validation) associated with an objects
get/setoperations. From php.net:Object properties may now have additional logic associated with their get and set operations. Depending on the usage, that may or may not make the property virtual, that is, it has no backing value at all.
Resources:Consider the following:If you’re looking for even more background into not just the impact of property hooks, but also the history behind the RFC process in conjunction with Asymmetrics Visibility to replace the older Property Accessors RFC, be sure to check out the great article by Larry Garfield on the topic on the PHP foundation website - How Property Hooks Happened. -
Asymmetric visibility
While the visibility of
getandsetobject operations have historically been “symmetric” - that is, both must bepublic,private, orprotected- PHP 8.4 allows for asymmetrics definitions in your objects. From php.net:Object properties may now have their
Resources:setvisibility controlled separately from thegetvisibility. -
Lazy objects
PHP 8.4 takes the responsibility of the lazy-initialization of object out of userland, bringing it into the PHP engine itself.
From php.net:
It is now possible to create objects whose initialization is deferred until they are accessed. Libraries and frameworks can leverage these lazy objects to defer fetching data or dependencies required for initialization. Object properties may now have their
Resources:setvisibility controlled separately from thegetvisibility.