防止PhpStorm中variable变量报错
Prevent error reporting for variable variable in PhpStorm
我有这段代码,但收到关于两个 "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 不报告这个 "error"?
编辑:
/** @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 */
我有这段代码,但收到关于两个 "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 不报告这个 "error"?
编辑:
/** @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 */