Permalink
Browse files

Fix #679: Check for local variables and treat them accordingly

On isset do not convert a variable to "not local", to prevent
previous code from getting invalidated.
  • Loading branch information...
steffen
steffen committed May 2, 2015
1 parent e8b442d commit a760a744da599605cd1b86fe4bbf02f4a243f129
Showing with 7 additions and 6 deletions.
  1. +3 −3 Library/Operators/Other/IssetOperator.php
  2. +4 −3 Library/Statements/Let/ArrayIndex.php
@@ -98,17 +98,17 @@ public function compile(array $expression, CompilationContext $compilationContex
case 'variable':
$indexVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $left['right']);
$indexVariable->setLocalOnly(false);
$indexVariableName = ($indexVariable->isLocalOnly() ? '&' : '') . $indexVariable->getName();
switch ($indexVariable->getType()) {
case 'int':
case 'long':
return new CompiledExpression('bool', 'zephir_array_isset_long(' . $variable->getName() . ', ' . $indexVariable->getName() . ')', $left['right']);
return new CompiledExpression('bool', 'zephir_array_isset_long(' . $variable->getName() . ', ' . $indexVariableName . ')', $left['right']);
case 'variable':
case 'string':
return new CompiledExpression('bool', 'zephir_array_isset(' . $variable->getName() . ', ' . $indexVariable->getName() . ')', $left['right']);
return new CompiledExpression('bool', 'zephir_array_isset(' . $variable->getName() . ', ' . $indexVariableName . ')', $left['right']);
default:
throw new CompilerException('[' . $indexVariable->getType() . ']', $expression);
@@ -190,19 +190,20 @@ protected function _assignArrayIndexSingle($variable, ZephirVariable $symbolVari
case 'variable':
$variableIndex = $compilationContext->symbolTable->getVariableForRead($exprIndex->getCode(), $compilationContext, $statement);
$variableIndexName = ($variableIndex->isLocalOnly() ? '&' : '') . $variableIndex->getName();
switch ($variableIndex->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$codePrinter->output('zephir_array_update_long(&' . $variable . ', ' . $variableIndex->getName() . ', &' . $symbolVariable->getName() . ', ' . $flags . ', "' . Compiler::getShortUserPath($statement['index-expr'][0]['file']) . '", ' . $statement['index-expr'][0]['line'] . ');');
$codePrinter->output('zephir_array_update_long(&' . $variable . ', ' . $variableIndexName . ', &' . $symbolVariable->getName() . ', ' . $flags . ', "' . Compiler::getShortUserPath($statement['index-expr'][0]['file']) . '", ' . $statement['index-expr'][0]['line'] . ');');
break;
case 'string':
$codePrinter->output('zephir_array_update_zval(&' . $variable . ', ' . $variableIndex->getName() . ', &' . $symbolVariable->getName() . ', ' . $flags . ');');
$codePrinter->output('zephir_array_update_zval(&' . $variable . ', ' . $variableIndexName . ', &' . $symbolVariable->getName() . ', ' . $flags . ');');
break;
case 'variable':
$codePrinter->output('zephir_array_update_zval(&' . $variable . ', ' . $variableIndex->getName() . ', &' . $symbolVariable->getName() . ', ' . $flags . ');');
$codePrinter->output('zephir_array_update_zval(&' . $variable . ', ' . $variableIndexName . ', &' . $symbolVariable->getName() . ', ' . $flags . ');');
break;
default:
throw new CompilerException("Variable: " . $variableIndex->getType() . " cannot be used as array index", $statement);

0 comments on commit a760a74

Please sign in to comment.