/**
* Adds a variable to the symbol table
*
* @param int $type
* @param string $name
* @param CompilationContext $compilationContext
* @param mixed $defaultValue
* @return Variable
*/
public function addVariable($type, $name, CompilationContext $compilationContext, $defaultValue = null)
{
$variable = new Variable($type, $name, $compilationContext->currentBranch, $defaultValue);
if ($type == 'variable') {
if ($this->localContext) {
/**
* Checks whether a variable can be optimized to be static or not
*/
if ($this->localContext->shouldBeLocal($name)) {
$variable->setLocalOnly(true);
}
}
}
$this->variables[$name] = $variable;
return $variable;
}