2

I recently migrated from PHP 5.6 to PHP 7.3 and trying to fix all my websites and keep them up to date.

On my Wordpress theme I get a lot of:

Indirect access to variables, properties and methods will be evaluated strictly in left-to-right order since PHP 7.0. Use curly braces to remove ambiguity.

The code in question is always:

global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}

Can someone please help, what is the right way to do this in PHP7 because I am confused. The error if specific to the if line.

Did a search on here and on Google and came up with nothing that was helpful. Tried braces and brackets, nothing.

I tried this and it did not help:

global $options;

foreach ($options as $value) {
    if (isset($value['id']) && get_option( $value['id'] ) === FALSE && isset($value['std'])) { $$value['id'] = $value['std']; }
    elseif (isset($value['id'])) { $$value['id'] = get_option( $value['id'] ); }
}
Rasclatt
  • 12,498
  • 3
  • 25
  • 33

1 Answers1

5

I think what it's referring to are variable variables, so try ${$value['id']} instead of $$value['id']:

foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) {
        ${$value['id']} = $value['std'];
    } else {
        ${$value['id']} = get_settings( $value['id'] );
    }
}

Here is the relevant documentation from the PHP upgrade notes

Rasclatt
  • 12,498
  • 3
  • 25
  • 33