Syntax error, unexpected ')' at DrupalImageCaption.php

Created on 31 January 2023, almost 2 years ago
Updated 1 February 2023, almost 2 years ago

Problem/Motivation

PHP Parse error: syntax error, unexpected ')' in web/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php on line 38

    $instance = new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
    );

Steps to reproduce

Installed Drupal core 9.5.2 on PHP 7.4.
Error was shown in browser console in various site page requests.

Proposed resolution

Remove the trailing comma, a trailing comma is only allowed in array() or list() constructs.

    $instance = new static(
      $configuration,
      $plugin_id,
      $plugin_definition
    );
💬 Support request
Status

Closed: works as designed

Version

9.5

Component

ckeditor.module

Created by

🇬🇷Greece mariaioann

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mariaioann
  • Status changed to Postponed: needs info almost 2 years ago
  • Please confirm the PHP version.

  • 🇬🇷Greece mariaioann

    PHP version is 7.4.

  • The inability to support trailing commas in function calls points to that PHP is actually < 7.3 on that system. Can you verify?

  • This pretty much shows what I mean:

    # docker run -it php:7.4-cli /bin/sh
    # php -a
    Interactive shell
    
    php > $foo = 'bar';
    php > var_dump($foo,);
    string(3) "bar"
    
    
    # docker run -it php:7.2-cli /bin/sh
    # php -a
    Interactive shell
    
    php > $foo = 'bar';
    php > var_dump($foo,);
    
    Parse error: syntax error, unexpected ')' in php shell code on line 1
    
  • This is a more concrete demonstration:

    $ docker run -it -v $PWD:/drupal php:7.4-cli /bin/sh
    # cd /drupal
    # php -l core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php
    No syntax errors detected in core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php
    # exit
    $ docker run -it -v $PWD:/drupal php:7.2-cli /bin/sh
    # cd /drupal
    # php -l core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php
    
    Parse error: syntax error, unexpected ')' in core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php on line 39
    Errors parsing core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php
    
  • 🇬🇷Greece mariaioann

    Correct, trailing commas in functions are allowed from PHP 7.3+.
    I do have PHP 7.4.
    I should have mentioned that the error appears in browser console when using ajax in views, and the exact error message is the following:

    Drupal.AjaxError {message: 'An AJAX HTTP error occurred.HTTP Result Code: 20…rc/Plugin/CKEditorPlugin/DrupalImageCaption.php).', name: 'AjaxError'}
    message: "An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows.
    Path: /en/quickedit/attachments 
    StatusText: OK
    ResponseText: ParseError: syntax error, unexpected &#039;)&#039; in Composer\\Autoload\\includeFile() (line 39 of web/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php)."
    Error at http://local-d9/core/misc/ajax.js?v=9.5.2:642:3
    
  • 🇬🇷Greece mariaioann

    The same error is thrown at: /admin/config/content/formats/manage/full_html
    My composer version is 1.10.26 if it is relevant with composer autoloading.

    ParseError: syntax error, unexpected ')' in Composer\Autoload\includeFile() (line 39 of core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php).
    Composer\Autoload\includeFile('/home/drupal9/web/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php') (Line: 322)
    Composer\Autoload\ClassLoader->loadClass('Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImageCaption')
    spl_autoload_call('Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImageCaption')
    class_exists('Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImageCaption') (Line: 96)
    Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass('drupalimagecaption', Array, 'Drupal\ckeditor\CKEditorPluginInterface') (Line: 17)
    Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('drupalimagecaption', Array) (Line: 83)
    Drupal\Component\Plugin\PluginManagerBase->createInstance('drupalimagecaption') (Line: 146)
    Drupal\ckeditor\CKEditorPluginManager->getButtons() (Line: 191)
    Drupal\ckeditor\Plugin\Editor\CKEditor->buildConfigurationForm(Array, Object) (Line: 165)
    editor_form_filter_format_form_alter(Array, Object, 'filter_format_edit_form') (Line: 562)
  • All evidence is that this is not PHP 7.4.

  • 🇬🇷Greece mariaioann

    OK, fair enough. Although both drush status and php --version report using PHP 7.4
    and I have explicitly set php version to 7.4 with:

    sudo a2enmod php7.4
    sudo update-alternatives --set php /usr/bin/php7.4

    maybe I have a misconfiguration at some part of my stack that hardcodes the php version to < 7.3.
    In that case, I suppose that this issue can be closed.

  • Status changed to Closed: works as designed almost 2 years ago
  • drush status and php --version are CLI commands. That site is certainly using a different version on the web. The PHPINFO section of the Drupal status report page will report the true version.

Production build 0.71.5 2024