I have a program that is written in PHP. The current version is 7.4 and everything works great.
Today I have upgraded the PHP version in composer.json to 8.2, and everything still worked. Now the question. Is my software now really on the latest version of PHP, or do I still need to do something?
Is it necessary to update the code too? Enums are new for example.
Earlier the enum looked like this in my code:
use ElaoEnumSimpleChoiceEnum;
final class LogReason extends SimpleChoiceEnum
{
public const NEW_REGISTRATION = 'NEW_REGISTRATION';
}
So is it necessary to update that? Or is that OK as long as it works?
3
Answers
To be sure that your software is now running with php8.2, you can check it by calling the phpinfo() function.
BUT you need to be sure that all of your code is still working. To do this, you can run the testsuite of your application if provided.
I suggest you to read the backward incompatible changes and check that the code isn’t using it. And you have to do it three times, one time per version (8.0, 8.1, 8.2) You should do it for the deprecated features, so migrations for PHP9 will be easier.
A you have upgraded composer.json, a lot of libraries have upgraded too. So, some manual tests could be a good idea in dev then qualification environment.
About the enum type, it isn’t necessary to upgrade your code (but a good idea for maintainability).
Updating the PHP version number in
composer.json
only tells composer which version of PHP your project should use. It uses it to decide which packages are compatible with your application.E.g. if you have
"php": "8.2"
then it will only install versions of packages that are compatible with PHP 8.2.It’ll also prevent you from running
composer install
etc in an environment with the wrong version of PHP installed.To actually upgrade your PHP version you are using, you’ll need to install it in the environment your application is running in (on your server, VM, Docker container, XAMPP, MAMP, local OS, WSL or whatever).
When we talk about "versions of PHP", what we generally mean is "versions of the software that executes your PHP scripts". (Theoretically, we could mean "the version of the language specification that that software implements", but PHP has no external language standard, so the software essentially is the specification.)
As an analogy, imagine you buy a new computer, and plug in your existing keyboard. There are three things you might want to check:
For a PHP upgrade, you can ask the same three questions: