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 1Steps to reproduce
- Install or update filefield_paths to 1.0.0-rc2 on an environment running Drupal 10 with PHP 8.1.
- 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.
Issue fork filefield_paths-3622262
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
Comment #3
cicciobat commentedComment #5
decipheredThanks 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. Thephpunitfailure you saw on it came from a change in the GitLab CI templates rather than from this fix, and8.x-1.xnow carries the fix for that too.My commit declares
php: 8.2in 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 thereadonlyclasses. 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.Comment #6
cicciobat commentedHi deciphered, thanks for the update and for adding those extra fixes! Everything looks great.