Problem/Motivation

When running 'drush csim -y' drush crashes with a PHP syntax error:
ParseError: syntax error, unexpected 'EntityTypeRepositoryInterface' ( T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in Composer\Autolo ad\includeFile() (line 40 of /home/strcom/public_test/releases/dev-master-111/we b/modules/contrib/dynamic_entity_reference/src/Plugin/Field/FieldWidget/DynamicE ntityReferenceWidget.php)

I found this out to be because two classes declare properties with the optional type introduced in PHP7.4.

Steps to reproduce

Run the above command on a Drupal 9 site with PHP 7.3 and this module

Proposed resolution

There are two options:
1. Mark this module as only compatible with PHP 7.4+
2. Change the two classes to remove the type in the property declarations

I am in favour of option 2 and supply a patch for this. I am in favour of this because of incompatibility that I have found between PHP 7.4 and twig requiring twig v1.43.0+ or v2.10.0+ which was an issue for me (I forget why) and because this feature of PHP7.4 has not been used elsewhere in this module.

Remaining tasks

Decide on solution and implement

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
php-7.3-compatability-fix.patch1.79 KBrory downes

Comments

Rory Downes created an issue. See original summary.

jibran’s picture

Status: Active » Needs work

Option 2 is not the way to go here especially after #3246916: Drop D8, D9.2, and PHP 7.3 support. Can I please have a patch for option 1?

If you want PHP 7.3 support please use 8.x-2.0-alpha15.

rory downes’s picture

Thanks for your feedback jibran and your recommendations.

The patch on ticket https://www.drupal.org/project/dynamic_entity_reference/issues/3246916 works for option 1.

However, no patch will work for this until committed and a new release created as changes to composer.json have to be in the release to have an impact.

Regards Rory

jibran’s picture

Title: Module flagged as compatible with PHP 7.3 but it requires PHP 7.4+ » Bump PHP version to 7.4
Version: 8.x-2.0-alpha16 » 8.x-2.x-dev

  • jibran committed 358b6bd on 8.x-1.x
    Issue #3258911 by Rory Downes, jibran: Bump PHP version to 7.4
    

  • jibran committed 6d0c1fc on 8.x-2.x
    Issue #3258911 by Rory Downes, jibran: Bump PHP version to 7.4
    
jibran’s picture

Status: Needs work » Fixed

Pushed a fix to both 1.x and 2.x branches. Will create a new release in a bit.

dpi’s picture

Issue tags: -PHP 7.3, -syntax error +PHP compatibility
faesch@gmx.de’s picture

This now broke my update.php due to incompatibility to PHP 7.3 (which I'm using).
I just checked and composer.json still requires >= 7.3.

Forcing version 1.13 in composer so I can run updates as I can't switch to PHP 7.4.

rory downes’s picture

m-p-j - note in comment #2 that jibran says 8.x-2.0-alpha15 also supports PHP7.3 - just in case that is useful to you.
Regards Rory

sam452’s picture

composer require 'drupal/dynamic_entity_reference:^2.0@alpha' returns the latest alpha which enforces PHP 7.4. Thankfully alpha15 is available. My Composer fu is small. How should I craft my composer call to get this specific alpha?

rory downes’s picture

sam452 change the '^2.0@alpha' to '2.0.0-alpha15' should constrain your project to alpha15.
Regards Rory

jibran’s picture

Sorry folks, I'll try to create a new release later this week with the proper fix.

  • jibran committed 9c3c7b9 on 8.x-1.x
    Issue #3258911 by jibran: Follow-up: Bump PHP version to 7.4
    

  • jibran committed 37ff320 on 8.x-2.x
    Issue #3258911 by jibran: Follow-up: Bump PHP version to 7.4
    
jibran’s picture

Version number is fixed in composer.json and all sub-modules.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

nojj’s picture

Just tried to install Version 1.16. Previous installed 1.13.
Getting:
Package drupal/dynamic_entity_reference at version ^1.16 has requirements incompatible with your PHP version, PHP extensions
and Composer version:
- drupal/dynamic_entity_reference 1.16.0 requires php >=7.4 which does not match your installed version 7.3.33.

I switched to PHP 7.4 before and in Drupal status information PHP 7.4.2 is shown.

Any tipps to solve this?

thanks in advance

jibran’s picture

Maybe try with composer install with --ignore-platform-reqs option.

nojj’s picture

seems a little bit risky. (never done that)
Strange thing: I have a local copy of that Drupal installation, and there I don't get that error, when running PHP 7.4.
maybe I can look somewhere else ?