BiologicalRecordsCentre / iRecord

Repository to store and track enhancements, issues and tasks regarding the iRecord website.
http://irecord.org.uk
2 stars 1 forks source link

Update code for compatibility with PHP8 #1047

Closed JimBacon closed 1 month ago

JimBacon commented 3 years ago

PHP 7.3 is approaching end of life in Dec 21. The most recent release is PHP 8.0. There is also PHP 7.4 with EOL in Nov 22.

To future-proof iRecord, we must ensure our code is compatible with PHP 8.0. This affects various components we have developed for which separate issues will be raised.

Drupal 7.79, released 7/4/2021, "is the first where D7 core's test suite passes tests in PHP 8.0. However, there may be remaining problems with PHP 8 in core, and it's very likely that there are problems in contrib." Drupal 8, which reaches end of life before Drupal 7 (Nov 21 and Nov 22 respectively), does not support PHP 8.0 Drupal 9.1 and upwards supports PHP 8.0

A move to PHP 8.0 therefore implies a move to Drupal 9. There is already an issue for this, https://github.com/BiologicalRecordsCentre/iRecord/issues/980

In order not to force other users of Indicia to upgrade to Drupal 9, while adding compatibility with PHP 8.0, backwards compatibility with PHP 7.3 and PHP 7.4 should be maintained.

JimBacon commented 3 years ago

There is a tool for running checks on PHP compatibility which may be helpful, https://github.com/PHPCompatibility/PHPCompatibility

To test it out I performed the following steps on my Linux development system (which already had PHP installed) as follows.

  1. Installed Composer
    1. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    2. HASH=756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3
    3. php -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH''') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    4. sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
  2. Installed the xmlwriter extension for PHP as required by CodeSniffer. sudo apt-get install php-xml
  3. Installed PHP CodeSniffer 3.6.0 globally. composer global require "squizlabs/php_codesniffer=*"
  4. Installed PHP Compatibility 9.3.5 globally. composer global require "phpcompatibility/php-compatibility=*"
  5. Added ~/.config/composer/vendor/bin to PATH in ~/.bashrc so the CodeSniffer executable can be found.
  6. Told CodeSniffer about PHP Compatability phpcs --config-set installed_paths ~/.config/composer/vendor/phpcompatibility/php-compatibility
  7. Confirmed that PHP Compatibility was present in CodeSniffer using phpcs -i
  8. Tested the current directory for compatibility with PHP 7.3 and up with phpcs -p . --standard=PHPCompatibility --runtime-set testVersion 7.3-
BirenRathod commented 1 year ago

https://github.com/Indicia-Team/warehouse/issues/431