PHPSA\Context::modifyReferencedVariables PHP Méthode

modifyReferencedVariables() public méthode

Updates all references on the given variable.
public modifyReferencedVariables ( Variable $variable, $type, $value )
$variable Variable
$type
$value
    public function modifyReferencedVariables(Variable $variable, $type, $value)
    {
        foreach ($this->symbols as $symbol) {
            $referencedTo = $symbol->getReferencedTo();
            if ($referencedTo) {
                if ($referencedTo === $variable) {
                    $symbol->modify($type, $value);
                }
            }
        }
    }

Usage Example

Exemple #1
0
 protected function compileVariableDeclaration(CompiledExpression $variableName, CompiledExpression $value, Context $context)
 {
     switch ($variableName->getType()) {
         case CompiledExpression::STRING:
             break;
         default:
             $context->debug('Unexpected type of Variable name after compile');
             return new CompiledExpression();
     }
     $symbol = $context->getSymbol($variableName->getValue());
     if ($symbol) {
         $symbol->modify($value->getType(), $value->getValue());
         $context->modifyReferencedVariables($symbol, $value->getType(), $value->getValue());
     } else {
         $symbol = new \PHPSA\Variable($variableName->getValue(), $value->getValue(), $value->getType(), $context->getCurrentBranch());
         $context->addVariable($symbol);
     }
     $symbol->incSets();
 }