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')
    );
  }
CommentFileSizeAuthor
#8 3233108-error-syntax-error.patch472 bytesj-barnes

Comments

LaurentD created an issue. See original summary.

laurentd’s picture

Title: Error: syntax error, unexpected ')' in ../EditorImagePopupDialog.php, line 46 » Error: syntax error, unexpected ')'
Issue summary: View changes
laurentd’s picture

Issue summary: View changes
laurentd’s picture

Issue summary: View changes
mohit.bansal623’s picture

@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

laurentd’s picture

@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.

  callfunc(1, 2, );

A trailing comma is only allowed in array() or list()constructs.

laurentd’s picture

Seems 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.

j-barnes’s picture

StatusFileSize
new472 bytes

Hopefully this helps someone.

laurentd’s picture

As expected #8 fixes the problem.

mohit.bansal623’s picture

Makes sense now. Thanks for clarifying. It's version related only.

mohit.bansal623’s picture

Status: Active » Needs review

jaykandari’s picture

Status: Needs review » Fixed

Looks good. Merged to 2.x.
Thank you for the contributions :)

Status: Fixed » Closed (fixed)

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