I've been using a couple of reference variables with PHP 5.5 like this, from the result of a MySQL query:
$sql="SELECT `name`, `value` FROM `maindatabase`.`systemProtect` WHERE `name`='IV' || `name`='passPhrase'";
$result=mysqli_query($serverConn, $sql);
while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)){
$$row['name']=$row['value'];
}
Whilst I'm sure it might not be the best way to do things, it worked fine for my needs.
I upgraded to PHP 7.4 and I get a an error: Notice: Array to string conversion
Through a fair bit of trial and error, I've fixed this by using some additional {} The code is now
$sql="SELECT `name`, `value` FROM `maindatabase`.`systemProtect` WHERE `name`='IV' || `name`='passPhrase'";
$result=mysqli_query($serverConn, $sql);
while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)){
${$row['name']}=$row['value'];
}
Now everything is working again, but I'd really like to understand why - what is it that the {} are doing in this case? I'm assuming it's because the variable is part of an array... but this wasn't required before.
Thanks for any insight.