Prevent error reporting for variable variable in PhpStorm

喜你入骨 提交于 2019-12-24 03:50:19

问题


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);

回答1:


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 */


来源:https://stackoverflow.com/questions/31730846/prevent-error-reporting-for-variable-variable-in-phpstorm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!