Error: [] operator not supported for strings in theme_cs_adaptive_image_formatter()

Created on 10 June 2021, over 4 years ago
Updated 20 September 2025, 21 days ago

Problem/Motivation

I updated CS Adaptive Image to CS Adaptive Image 7.x-1.1 on my Drupal 7 Site and it started throwing this error on every page using CS Adaptive Image:

Error: [] operator not supported for strings in theme_cs_adaptive_image_formatter() (line 252 of /code/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module).

Steps to reproduce

Update to CS Adaptive Image 7.x-1.1 on a server running PHP 7.1.33

Proposed resolution

Add one line above line 252 to first define an empty array before giving the array a value.

It looks like the error may be caused by a PHP syntax change in PHP 7.1

See this resource: https://wordpress.org/support/topic/fatal-error-operator-not-supported-f...

diff --git a/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module b/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module
index fd4790384..bf92be20c 100644
--- a/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module
+++ b/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module
@@ -249,6 +249,7 @@ function theme_cs_adaptive_image_formatter($variables) {
   // to serve an adapted image. Some browsers cannot access the
   // children of a <noscript> element, thus all the data needs to be
   // attached to the <noscript> element.
+  $image['attributes']['class'] = [];
   $image['attributes']['class'][] = 'adaptive-image';
   $attributes['class'][] = 'adaptive-image';
   if (isset($variables['breakpoint_styles'])) {
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States carroll_webprog

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024