Testing Compatibility with a PHP version

New versions of the PHP programming language are regularly released and older versions are retired. It’s important to check compatibility of your code with the new PHP version as the language does evolve and change, functions and syntax your code uses may no longer be available in the new version. You can use code sniffers to check your code for compatibility with a particular version.

Install PHP CodeSniffer

Begin by installing PHP CodeSniffer following the instructions in the project README on GitHub.

Checkout code from repository (if using)

If your code is committed to a repository, checkout the code to your local file system.

Run the PHP CodeSniffer

Run the following command to check compatibility. Where {php-version} is replaced with the PHP version e.g. 7.4

php -d memory_limit=-1 /path/to/phpcs.phar -p --ignore="*/vendor/*" --extensions=php --runtime-set testVersion {php-version} --standard=PHPCompatibility /path/to/repository/

An example of the command to check for compatibility with PHP 7.4

php -d memory_limit=-1 /path/to/phpcs.phar -p --ignore="*/vendor/*" --extensions=php --runtime-set testVersion 7.4 --standard=PHPCompatibility /path/to/repository/

Analysing the results

The command will output results similar to

$ php -d memory_limit=-1 /path/to/phpcs.phar -p --ignore="*/vendor/*" --extensions=php --runtime-set testVersion 7.4 --standard=PHPCompatibility /path/to/repository/    
............................................................   60 / 1981 (3%)
............................................................  120 / 1981 (6%)
............................................................  180 / 1981 (9%)
............................................................  240 / 1981 (12%)
............................................................  300 / 1981 (15%)
............................................................  360 / 1981 (18%)
............................................................  420 / 1981 (21%)
............................................................  480 / 1981 (24%)
................................W...........................  540 / 1981 (27%)
............................................................  600 / 1981 (30%)
............................................................  660 / 1981 (33%)
............................................................  720 / 1981 (36%)
............................................................  780 / 1981 (39%)
............................................................  840 / 1981 (42%)
............................................................  900 / 1981 (45%)
............................................................  960 / 1981 (48%)
............................................................ 1020 / 1981 (51%)
............................................................ 1080 / 1981 (55%)
............................................................ 1140 / 1981 (58%)
............................................................ 1200 / 1981 (61%)
............................................................ 1260 / 1981 (64%)
............................................................ 1320 / 1981 (67%)
............................................................ 1380 / 1981 (70%)
............................................................ 1440 / 1981 (73%)
............................................................ 1500 / 1981 (76%)
............................................................ 1560 / 1981 (79%)
............................................................ 1620 / 1981 (82%)
............................................................ 1680 / 1981 (85%)
..............................W............................. 1740 / 1981 (88%)
............................................................ 1800 / 1981 (91%)
............................................................ 1860 / 1981 (94%)
..........W................................................. 1920 / 1981 (97%)
............................................................ 1980 / 1981 (100%)
.                                                            1981 / 1981 (100%)



FILE: /path/to/jadu/XFormsPro/Form/Advanced/Logics/LogicInputRetracer.php
--------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------
 1 | WARNING | No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.
--------------------------------------------------------------------------------------------


FILE: /path/to/jadu/XFormsPro/BlueBadge/Resolver/BlueBadgeApplicationResolver.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
 1148 | WARNING | The left-associativity of the ternary operator has been deprecated in PHP 7.4. Multiple consecutive ternaries detected. Use parenthesis to clarify the order in which the operations should be executed
----------------------------------------------------------------------------------------------------


FILE: /path/to/jadu/XFormsPro/Workflow/WorkflowService.php
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------
 1 | WARNING | No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.
-----------------------------------------------------------------------------

Time: 26.42 secs; Memory: 28MB

Verify each warning and error that has been output and correct as required.

The PHP project provides guides for migrating from one version to another version which can be used for reference https://www.php.net/manual/en/appendices.php

results matching ""

    No results matching ""