I am updating my WordPress site from PHP 5.5 to PHP 7.2.
PHP compatibility checker has advised the following for header & footer:
27 & 30 | ERROR | 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.
Line 24-33 reads:
---extract from Header.php---
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'] );
}
}
?>
---extract from Header.php---
Line 27 reads as:
$$value['id'] = $value['std'];**
Line 30 reads as:
$$value['id'] = get_option( $value['id'] );
How should I use curly braces to fix the two statements above?
It's the dynamic variable name $$value['id']
.
On previous/older PHP versions it was fine to declare it like that but starting PHP 7.0 you need to use curly braces to make it more readable/evident and avoid confusion:
${$value['id']} = $value['std'];
${$value['id']} = get_option( $value['id'] );
See PHP - Variable variables for more details.