Undefined variable on defining variable variables

366 views Asked by At

I want to import data from a .json file into a PHP file and dynamically, by using variable variables and a foreach loop, define new variables. However, PhpStorm doesn't recognize my variables and give me Undefined variable warnings. What to do?

Consider a file data.json with some data, and it exists and is readable. The main code is something like this:

foreach (json_decode(file_get_contents("data.json"), true) as $varName => $value)
    $$varName = $value;

Note: I don't want neither to use PHPDoc, nor to disable "undefined variable" inspection (thanks LazyOne).

UPDATE: Thanks to LazyOne's comment, I'll use PHP files instead of JSON ones to save data.

0

There are 0 answers