public function visitVar(Node $node) : UnionType
{
// $$var or ${...} (whose idea was that anyway?)
if ($node->children['name'] instanceof Node && ($node->children['name']->kind == \ast\AST_VAR || $node->children['name']->kind == \ast\AST_BINARY_OP)) {
return MixedType::instance()->asUnionType();
}
// This is nonsense. Give up.
if ($node->children['name'] instanceof Node) {
return new UnionType();
}
$variable_name = $node->children['name'];
if (!$this->context->getScope()->hasVariableWithName($variable_name)) {
if (Variable::isSuperglobalVariableWithName($variable_name)) {
return Variable::getUnionTypeOfHardcodedGlobalVariableWithName($variable_name, $this->context);
}
if (!Config::get()->ignore_undeclared_variables_in_global_scope || !$this->context->isInGlobalScope()) {
throw new IssueException(Issue::fromType(Issue::UndeclaredVariable)($this->context->getFile(), $node->lineno ?? 0, [$variable_name]));
}
} else {
$variable = $this->context->getScope()->getVariableByName($variable_name);
return $variable->getUnionType();
}
return new UnionType();
}