Getting your code ready for PHP 8.5
PHP 8.5 was released about two months ago, so it should be stable enough to upgrade. I generally avoid big-bang releases, especially since I run multiple applications on a single server. To prevent a risky all-at-once upgrade and to verify that everything works correctly before switching PHP versions, I was looking for a way to upgrade the codebase beforehand.
Getting ready
To prepare an application for PHP 8.5, two changes are required.
First, allow the new PHP version in the version constraint inside the require section:
{
"require": {
"php": "^8.4 || ^8.5"
}
}
Second, define the target PHP version in the config section:
{
...
"config": {
"platform": {
"php": "8.5"
}
}
}
With this setting in place, Composer ensures that all updated packages are compatible with PHP 8.5—even if PHP 8.4 is still installed. For the sake of simplicity, it emulates PHP 8.5 during dependency resolution.
Updating the code
Now the dependencies can be updated to versions compatible with PHP 8.5. This can be done either incrementally or all at once.
For the incremental approach, start by identifying which packages are blocking the PHP 8.5 upgrade:
composer why-not php 8.5
This command lists all packages that currently prevent the update.
You can then update the blocking packages individually:
composer update vendor/package1 vendor/package2 --with-all-dependencies
This updates the specified packages and all related dependencies in the composer.lock file, while still respecting the version constraints defined in composer.json.
To update all dependencies at once, simply run:
composer update --with-all-dependencies
If the update fails, inspect the error output carefully. In most cases, version constraints are preventing certain packages from being updated. These constraints must be adjusted before continuing.
Once the update completes successfully, the updated code can be deployed to production. The application will still run on PHP 8.4. After all applications have been prepared this way, PHP 8.5 can be installed and the production server switched to the new version.
Conclusion
This approach makes it easy to prepare your codebase for a new PHP version, deploy the changes safely, and switch PHP versions with minimal downtime. For me, it significantly reduces deployment pressure and avoids last-minute surprises during the version upgrade.

