[solved] PHP 7 syntax problem with array access on variable variables

if($ops[0]=='ARRAY'){
    global $$ops[1];		
    echo select_builder($name, $$ops[1], POST_return($name,$defaultV), 'nokey', $extra, $default);
}

I’m getting
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /foo/bar.php on line 750

Did something about variable variables chage since 9 years ago?

Globals go in a function, but you shouldn’t be using it anyways. In a function, you would pass the parameters you want. Variable variables make code hard to follow.

Bingo! This is part of a massive function that seems to generate forms based on a peculiar string like 'Favorite Fruit,fruit_fav,select:ARRAY|fruitsArray'

I’ve got to either change global $ops[1]; to something that works exactly the same without killing PHP 7 or find where this functions is being used and rebuild the form from scratch.

I fixed it

$varVarName = $ops[1];
global $$varVarName;
Sponsor our Newsletter | Privacy Policy | Terms of Service