我有这段代码,并得到两个"undefined"变量的错误报告
$tables = [
'foo',
'bar',
'baz'
];
foreach ($tables as $table) {
$$table = $this->setUpTables($table, $prefix);
}
$all = $this->getBaz($foo,$bar); // those two are reported as undefined
是否有可能告诉PhpStorm不报告这个"错误"?
编辑:/** @var foo $foo */
/** @var bar $bar */
$all = $this->getBaz($foo,$bar);
在这种情况下,我认为使用更简单的语言特性会获胜。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 */