简体   繁体   中英

Prevent error reporting for variable variable in PhpStorm

I have this code and get an error reported for the two "undefined" variables

$tables = [
            'foo',
            'bar',
            'baz'
        ];
foreach ($tables as $table) {
    $$table = $this->setUpTables($table, $prefix);
}
$all = $this->getBaz($foo,$bar); // those two are reported as undefined

Is it possible to tell PhpStorm to not report this "error"?

EDIT:

/** @var foo $foo */
/** @var bar $bar */
$all = $this->getBaz($foo,$bar);

Using simpler language features wins in this case, I think. PhpStorm should also have no trouble figuring out which variables are in scope.

$products        = $this->setUpTables('products', $prefix);
$excludeRules    = $this->setUpTables('excludeRules', $prefix);
$excludedSellers = $this->setUpTables('excludedSellers', $prefix);
$livePricing     = $this->setUpTables('livePricing', $prefix);

$all = $this->getProducts($products, $livePricing);

If PhpStorm thinks a variable is out of scope when it is not, you can add this declaration within the scope.

/** @var variableName */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM