我有这个代码并报告了两个错误" undefined"变量
{'1': {
'12312004': {'var1': '234', 'var2': '456'},
'12312005': {'var1': '200', 'var2': '466'},
'12312006': {'var1': '760', 'var2': '656'},
'12312007': {'var1': '215', 'var2': '256'}},
'2': {
'5312006': {'var1': '234', 'var2': '456'},
'5312007': {'var1': '200', 'var2': '466'},
'5312008': {'var1': '760', 'var2': '656'},
'5312009': {'var1': '215', 'var2': '256'}}
}
是否有可能告诉PhpStorm不报告此错误"错误"?
编辑:
$tables = [
'foo',
'bar',
'baz'
];
foreach ($tables as $table) {
$$table = $this->setUpTables($table, $prefix);
}
$all = $this->getBaz($foo,$bar); // those two are reported as undefined
答案 0 :(得分:4)
我认为,在这种情况下,使用更简单的语言功能会获胜。 PhpStorm也应该毫不费力地确定哪些变量在范围内。
$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);
如果PhpStorm认为变量超出范围,则可以在范围内添加此声明。
/** @var variableName */