Problem/Motivation

After upgrading to filefield_paths 1.0.0-rc2, running drush cr results in a PHP parse error. Several classes in the module now use the readonly class modifier, which was introduced in PHP 8.2 and is not supported in PHP 8.1.
Error Output:

PHP Parse error:  syntax error, unexpected token "readonly", expecting "abstract" or "final" or "class" in /var/www/html/modules/contrib/filefield_paths/src/Hook/EntityWithFileField.php on line 17

Parse error: syntax error, unexpected token "readonly", expecting "abstract" or "final" or "class" in /var/www/html/modules/contrib/filefield_paths/src/Hook/EntityWithFileField.php on line 17
 [warning] Drush command terminated abnormally.
Failed to run drush cr: exit status 1

Steps to reproduce

  1. Install or update filefield_paths to 1.0.0-rc2 on an environment running Drupal 10 with PHP 8.1.
  2. Run drush cr.

Proposed resolution

  • Option A (Recommended): Update the module's composer.json file to explicitly set the minimum PHP version constraint to ^8.2.
  • Option B: Refactor the classes to remove the readonly modifier on the class level and instead apply readonly to individual class properties so that PHP 8.1 compatibility is maintained.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cicciobat created an issue. See original summary.

cicciobat’s picture

Status: Needs work » Needs review

deciphered made their first commit to this issue’s fork.

deciphered’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for reporting this and for the merge request, cicciobat. Your commit is unchanged, rebased onto 8.x-1.x, with one commit of mine on top, and the merge request is green. The phpunit failure you saw on it came from a change in the GitLab CI templates rather than from this fix, and 8.x-1.x now carries the fix for that too.

My commit declares php: 8.2 in the info file for sites that install without Composer, states the requirement in the README and the CHANGELOG, and adds a unit test that the declared minimum covers the readonly classes. 8.x-1.0-rc2 shipped with no PHP constraint, so Composer on PHP 8.1 still resolves to it. Sites on PHP 8.1 should pin 8.x-1.0-rc1 until they can move to PHP 8.2.

cicciobat’s picture

Hi deciphered, thanks for the update and for adding those extra fixes! Everything looks great.

  • deciphered committed bc3b90f5 on 8.x-1.x
    fix(#3622262): declare PHP 8.2 and test Drupal 10 on it