Problem/Motivation
PHP Parse error: syntax error, unexpected ')' in /src/Form/EditorImagePopupDialog.php on line 46
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
);
}
Steps to reproduce
Installed version 2.x-dev; running Drush command drush cr will terminate abnormally due to an unrecoverable error.
Proposed resolution
Remove the trailing comma, a trailing comma is only allowed in array() or list() constructs.
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager')
);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3233108-error-syntax-error.patch | 472 bytes | j-barnes |
Comments
Comment #2
laurentd commentedComment #3
laurentd commentedComment #4
laurentd commentedComment #5
mohit.bansal623 commented@laurentd, I am not able to replicate this issue.
I have enabled this module on both D8 and D9 site and the module got successfully enabled. There is no such error on clearing cache.
D8 version - 8.9.18
D9 version - 9.2.4
Module version link - git clone --branch '2.x' https://git.drupalcode.org/project/image_popup.git
Comment #6
laurentd commented@mohit.bansal623, I am running Drupal 8 and PHP 7.2, but there shouldn't be a trailing comma.
Unexpected ')'
Absent function parameter
You cannot have stray commas last in a function call. PHP expects a value there and thusly complains about an early closing ) parenthesis.
A trailing comma is only allowed in
array()orlist()constructs.Comment #7
laurentd commentedSeems like a PHP version related issue:
PHP RFC: Allow a trailing comma in function calls
https://wiki.php.net/rfc/trailing-comma-function-calls
As of PHP 7.3 trailing comma functions calls are allowed; but prior PHP versions gives a syntax error. Would be nice to implement this minor change to allow an easy Drupal 9 upgrade path still on PHP 7.2 environments.
Comment #8
j-barnes commentedHopefully this helps someone.
Comment #9
laurentd commentedAs expected #8 fixes the problem.
Comment #10
mohit.bansal623 commentedMakes sense now. Thanks for clarifying. It's version related only.
Comment #11
mohit.bansal623 commentedComment #13
jaykandariLooks good. Merged to 2.x.
Thank you for the contributions :)