skip to Main Content

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


  1. 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).

    Login or Signup to reply.
  2. 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).

    Login or Signup to reply.
  3. 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:

    1. Have you definitely plugged it into the right computer? You can look at the wires, or you can open Notepad and start typing something.
    2. Does it work fully with the new computer? Maybe it has special macro keys that open your favourite software, or perform a special move in your favourite game. You can test that those still do what you expect; or you can look at the instruction manual for what needs setting up on the new system.
    3. Are there new features you can use that you couldn’t before? Maybe the macro keys can do extra things now; but if you don’t make use of that, it doesn’t mean you’re not using your new computer.

    For a PHP upgrade, you can ask the same three questions:

    1. Are you definitely running with that version of the software? You can look at the system settings, or you can ask PHP directly using functions like phpinfo, phpversion.
    2. Is your program working correctly on the new version? Ideally, you’d have a nice suite of automated tests; more realistically, you can manually test functionality, keeping an eye on your error logs; you can also look up the migration guides in the PHP manual to see what you might need to change. Pay particular attention to the 7.4 to 8.0 migration since that is where the majority of "breaking" changes happened.
    3. Are there new features you can use that you couldn’t before? This is where enums come in – you can now use them if you want, but not using them doesn’t mean you’re not using PHP 8.2. Having a new way to do something doesn’t mean the old way will immediately, or ever, stop working.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search