Problem/Motivation

This is a follow-up to https://www.drupal.org/project/google_analytics/issues/3174214 where I mentioned that updating to 7.x-2.7 immediately crashed my site with no errors in the logs.

I was able to determine that it was in fact a PHP version issue, as some code using the short array syntax was committed.

Drush command terminated abnormally due to an unrecoverable error.                                           [error]
Error: syntax error, unexpected '[' in
/var/www/html/sites/all/modules/contrib/google_analytics/googleanalytics.module, line 457
      // Drupalism: When empty, $account->data is a boolean, not an array.
      if (!is_array($account->data)) {
          $account->data = [];
      }

should be

      // Drupalism: When empty, $account->data is a boolean, not an array.
      if (!is_array($account->data)) {
          $account->data = array();
      }

If we are expecting everyone using this module to be able to handle the short array syntax, we should add a requirements check so that people who cannot run this version do not attempt to update to it.

Comments

jenlampton created an issue. See original summary.

jenlampton’s picture

Status: Active » Needs review
StatusFileSize
new538 bytes

This old server appears to be running PHP 5.6, but I think the short array syntax was introduced in PHP 5.4?
I'm not sure exactly how I'm having this problem, but this patch did fix it for me ¯\_(ツ)_/¯

mglaman’s picture

Oh, wow, thanks. I'll commit this patch tomorrow and make another release. Thanks for finding the root cause.

  • mglaman committed 52867e47 on 7.x-2.x authored by jenlampton
    Issue #3349502 by jenlampton: PHP short array syntax committed to 7.x-2....
mglaman’s picture

Status: Needs review » Fixed

Thank you! Committed. I am actually waiting to release to review any other issues, I'll release next week.

Status: Fixed » Closed (fixed)

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