1

We have a large codebase and it's currently running in production on PHP 7.4. Now we're getting ready to upgrade to PHP 8.1 and so we've been asked to make sure the code is going to work when we upgrade.

We have phpcs of course, and this will detect things that have been completely removed by PHP 8.1 (or PHP8.0) to make sure that the code runs without fatal errors, but there are a bunch of things listed in the migration docs from php7.4 to php8.0 where behaviour will change and I don't see any warnings that if I upgrade to 8.0 then my code will behave differently. Or said another way, I'd like to be pointed to the exact places that I need to modify my code if I want the behaviour not to change after the upgrade.

To illustrate, here's a file test.php:

<?php

if(0 == "foo") {
    echo "this was true in php 7.4, you must be running 7.4 or lower\n";
} else {
    echo "this is false in php 8.0, you must be running 8.0 or higher\n";
}

Because of a change between PHP 7.4 and PHP 8.0 the behaviour of this code will differ depending on which version of php is running it, but I haven't found how phpcs can be made to warn me about this while I'm still on 7.4 and preparing to go to 8.0. I've tried:

composer global require squizlabs/php_codesniffer:^3 phpcompatibility/php-compatibility:^9
$(composer config -g home)/vendor/bin/phpcs \
    --standard=$(composer config -g home)/vendor/phpcompatibility/php-compatibility \
    --runtime-set testVersion 8.1 test.php

But this doesn't detect the if(0 == "foo") { which might break everything post upgrade...

There seem to be quite a few tools that check for backward compatibility but I guess I'm looking for checking forward compatibility.

Is this doable with phpcs? Or is there another static analysis tool that will help me prepare for an upgrade by catching these breaking changes? If not, what other ways of preparing for an upgrade do you recommend, considering a very large codebase?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Emmet O'Grady
  • 269
  • 2
  • 8

0 Answers0