I've tried running a site that uses (a subtheme of) AdaptiveTheme on the newly released PHP 7.1

I hit fatal errors.

Here are some of the errors in the dblog:

Warning: Illegal string offset 'media' in at_load_subtheme_conditional_styles() (line 488 of /{path}/sites/all/themes/adaptivetheme/at_core/inc/load.inc).

and similar complaints about the 3 lines of code after that.

Looking at that file, what's happening is this:

      $ie_style = '';
<em>{snip}</em>
            $ie_style['media'] = $media;
            $ie_style['condition'] = $condition;

What's wrong with that, you ask?

Well, if you look at the PHP documentation on array assignments, it says this:

Note: As of PHP 7.1.0, applying the empty index operator on a string throws a fatal error. Formerly, the string was silently converted to an array.

Put another way, you can look at the "backwards incompatibility" page of the release notes.

The empty index operator is not supported for strings anymore
Applying the empty index operator to a string (e.g. $str[] = $x) throws a fatal error instead of converting silently to array.

That's what's happening here: $ie_style is set to the empty string, then silently converted to an array the first time it's needed to become one: $ie_style['media'] = foo.

Probably, all that's needed is to change that empty-string assignment into $ie_style = array();, but I've not got time to test that now. I also don't want know at_core well enough to know if there might be unforeseen consequences of making that change.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JamesOakley created an issue. See original summary.

JamesOakley’s picture

Status: Active » Needs review
FileSize
584 bytes

Probably, all that's needed is to change that empty-string assignment into $ie_style = array();

Yep - the attached fixed this:

Jeff Burnz’s picture

Status: Needs review » Needs work
+++ b/at_core/inc/load.inc
@@ -476,7 +476,7 @@ function at_load_subtheme_conditional_styles($theme_name) {
+      $ie_style = array();

If we're going to support PHP 7 then may as well use the short array syntax, i.e. $arr = [];

JamesOakley’s picture

Just checking: That would cause problems for any PHP earlier than 5.4.

I know: nobody should be using PHP that old, as it's well past the cut-off for security updates. But does that mean we're at the stage where we can use syntax that breaks <5.4?

Jeff Burnz’s picture

Status: Needs work » Reviewed & tested by the community

Forgot this was D7. Lol.

Heres a funny stat - 1.7% of PHP installs are PHP 7.1

Lets go with the verbose syntax.

wizonesolutions’s picture

Patch works. +1 to committing this.

alexpott’s picture

Issue tags: -php7.1 +PHP 7.1
donaldwbabcock’s picture

Was a decision made regarding AT-7.x supporting php 7.1? I came across this after a client migrated hosting using a sub-theme of AT. Old PHP was 5.6.x, new is 7.1.x.

Drupal 7 official docs say 7 is supported, nothing about 7.1 specifically.

Interestingly 7.0.x and 5.6.x have a similar EOL dates. http://php.net/supported-versions.php

I'm seeing illegal offset of the following:
Warning: Illegal string offset 'path' in at_load_subtheme_conditional_styles() (line 491 of /sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
Warning: Illegal string offset 'path' in at_load_subtheme_conditional_styles() (line 490 of /sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
Warning: Illegal string offset 'condition' in at_load_subtheme_conditional_styles() (line 489 of /sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
Warning: Illegal string offset 'media' in at_load_subtheme_conditional_styles() (line 488 of /sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).

edvanleeuwen’s picture

Patch works.

It also resolved a message I got regarding not being able to load a CSS in my custom theme:

One or more CSS files were not found or does not exist: sites/all/themes/pr_covs/c.

I think the path was truncated in the former situation.

JamesOakley’s picture

This has been RTBC for a whisker under a year, and PHP 7.2 is due to be released next week (pending no major problems being found with the final RC).

Is there a reason why this hasn't been committed? Are you waiting for something else from other users? Happy to help if I can.

Jeff Burnz’s picture

Forgot about it, that would be the main reason. Life is busy.

JamesOakley’s picture

I know all about that. :-P

pbull’s picture

RTBC. +1 to merging this fix.

TheoRichel’s picture

I am on PHP 7.1.10-1+0~20170929170631.9+jessie~1.gbp501135 and Adaptive Theme 3.4 and AT Commerce 3.2 and I have applied this patch, but I keep on getting messages about missing css-files like:
CSS file missing or not found sites/all/themes/adaptivetheme/at_admin/css/ie-lte-9.css

Any help would be greatly appreciated.

ergophobe’s picture

TheoRichel - this is inherent in Adaptive Theme and it's derivatives and is unrelated to this issue. They generate files and sometimes if you move from one system to another (or install the themes by certain means), those files get lost, deleted or whatever.

All you have to do is go to the Appearance page, click the link for Settings for AT, and then save it. Those files will get regenerated and the error will go away.

If that doesn't do it, then you probably have some sort of file permissions issue that is preventing them from getting created.

marcoka’s picture

running: PHP 7.2.4 (cli) (built: Mar 28 2018 16:40:43) ( NTS )

patch works great. thank you
just resaving the settings page or permissions are not the problem here ergophobe. it is the php version, as said by others.

joseph.olstad’s picture

+1 commit this please someone, and cut a release

ergophobe’s picture

@marcoka - I understand that, but I did not think TheoRichel's question was related to this issue. I was trying to explain that (at least nobody else is having missing files as a result of this issue)

gnurob’s picture

The maintainer for AdaptiveThemes hasn't updated this project for 5 months. It's possible they don't realize a PHP7 bug exists. I have put in a request here (login required). It may help to include what versions you know are affected by this error, and any code that requires patching.

AdaptiveThemes is a nice piece of work. I hope it carries into future versions and I'm glad to support its ongoing development by paying for updates. Let's hope it doesn't die...

joshuautley’s picture

#2 and adding the file "lt-ie9.css" to the AT Admin Theme resolved the error for us.

Thank you!

Liam Morland’s picture

Version: 7.x-3.4 » 7.x-3.x-dev
AohRveTPV’s picture

For what it's worth, I had this problem and independently made the same code change as in the patch. So, #2 is one person more RTBC.

alysaselby’s picture

I just applied the patch in #2 to my 7.2 site and I am no longer seeing the error.

One or more CSS files were not found or does not exist: sites/all/themes/[mytheme]/c.

Thank you for the fix.

DanChadwick’s picture

@Jeff Burz: Super duper RTBC. Thanks for this theme!

alpiniste’s picture

As of the D7 release version AT Core 7.x-3.4 at the time of writing, the line number of the problem is 479, but the original patch works unmodified.

alpiniste’s picture

In fact, I have found the original patch is not enough for AT Core 7.x-3.4. The attached patch does the job (as far as I have encountered).

Dane Powell’s picture

Thanks, #26 worked for me.

broon’s picture

Confirming #26 to work, thank you.

joseph.olstad’s picture

FTLOG , someone (anyone) please request and take ownership of this project and push this patch asap or light a fire in the right place.

AohRveTPV’s picture

AohRveTPV’s picture

I've been granted co-maintainership, so I can push a fix for this.

How do you reproduce the bug(s) that #26 is supposed to fix? The problem I have is fixed by #2. I'm wondering if these are separate issues. One is treating a string as an array; the other is assigning a value to a key of an array when the array has not been previously declared, which I'm not sure is invalid. Tempted to just commit #2.

The following code works for me without error in PHP 7.1.8:

$foo['bar'] = 'baz';

Maybe others are running with a different PHP version or more error reporting?

alpiniste’s picture

Replying to #31 by AohRveTPV (thank you very much for co-maintaining this!):
What #26 fixes is exactly the same sort of PHP-version-dependent problem. In the release version of Adaptive Theme, a few lines had the same problem as the original of this thread, and that's what the patch fixes.

I can't give you a test case to reproduce it (apart from the fact it solved this problem in my site with the release version of Adaptive Theme, whereas the original patch to the dev version was inadequate), partly because I'm away at the moment, but I suppose it's obvious and simple enough...

AohRveTPV’s picture

alpiniste, I talked to some PHP people and they said it's fine in all versions to assign a value to an array key before the array is declared. I also can't reproduce the problem. So I'm not sure that the changes in #26 that are not in #2 are needed.

That is, doing this, without any prior code, is OK:

$foo['bar'] = 'baz';

In any case, this issue can be specifically for the problem of using a variable with a string value as an array in PHP >=7.1. We can solve any other PHP version incompatibilities as separate issues.

  • AohRveTPV committed d3e1bc3 on 7.x-3.x authored by JamesOakley
    Issue #2832900 by JamesOakley: PHP 7.1 no longer converts string to...
AohRveTPV’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

Anybody’s picture

Hi and thank you! Any plans for a new stable release where PHP 5.x is "dead"? :)

JamesOakley’s picture

There have been no commits to this project for 6 months. I think we were fortunate AohRveTPV stepped in as co-maintainer to commit the fix for this issue, but I think it's highly unlikely we'll get any more tagged releases.

joseph.olstad’s picture

@AohRveTPV , can you please tag a release, or assign maintainer role to someone who is able to ? (I could do it for you if you want).

most of contrib is ready for php 7.3.x

Drupal core 7.68 will be released December 4th with php 7.3.x support.

I've gone through popular modules my clients use and pushed up php 7.3.x compatible releases for those projects.

With that said, my clients mostly use the bootstrap based themes mostly however I'm sure there's a few with adaptive_theme still going strong.

april26’s picture

I applied the patches, cleared the cache but I'm still getting the errors, as well as the missing CSS errors. When I do a cron it disappears, but the next time the page loads it appears again.

I even get it when I switch to PHP 7.0.

The logs show it can't find the file, but in the file manager the generated files are visible (and were newly created when I saved the Settings). The missing files are in at-commerce-files rather than adaptive-theme-files, but I saved both.

Fortunately the website itself doesn't appear to be affected.

If I remember this is an Acquia theme. Considering they are totally committed to Drupal, I"m surprised they are so bad at fixing this properly? There are many designers who won't be able to implement this patch?

Aleet’s picture

Like april26 , I'm also getting errors after patching. Any help would be much appreciated. Running php 7.3.

    Warning: Illegal string offset 'media' in at_load_subtheme_conditional_styles() (line 488 of /home/iranolog/public_html/tork-multi/sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
    Warning: Illegal string offset 'condition' in at_load_subtheme_conditional_styles() (line 489 of /home/iranolog/public_html/tork-multi/sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
    Warning: Illegal string offset 'path' in at_load_subtheme_conditional_styles() (line 490 of /home/iranolog/public_html/tork-multi/sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
    Warning: Illegal string offset 'path' in at_load_subtheme_conditional_styles() (line 491 of /home/iranolog/public_html/tork-multi/sites/all/themes/adaptivetheme/adaptivetheme/at_core/inc/load.inc).
Aleet’s picture

Correction: I get the above errors only when running the Corolla subtheme. I'm not getting it on adpative itself or the Sky subthem.