diff --git a/src/CompiledExpression.php b/src/CompiledExpression.php index 3eb6b176..dcd5f37d 100644 --- a/src/CompiledExpression.php +++ b/src/CompiledExpression.php @@ -196,7 +196,7 @@ public static function fromZvalValue($value) */ public function canBeObject() { - return (boolean) ($this->type == self::OBJECT || $this->type & self::OBJECT); + return (boolean) ($this->type == self::OBJECT || $this->type == self::MIXED || $this->type & self::OBJECT); } /** diff --git a/src/Compiler/Expression.php b/src/Compiler/Expression.php index e71b198b..4500834d 100644 --- a/src/Compiler/Expression.php +++ b/src/Compiler/Expression.php @@ -388,13 +388,15 @@ public function passProperty(Node\Stmt\Property $st) /** * @param Node\Expr\Variable $expr + * @param mixed $value + * @param int $type * @return CompiledExpression */ - public function declareVariable(Node\Expr\Variable $expr) + public function declareVariable(Node\Expr\Variable $expr, $value = null, $type = CompiledExpression::UNKNOWN) { $variable = $this->context->getSymbol($expr->name); if (!$variable) { - $variable = new Variable($expr->name, null, CompiledExpression::UNKNOWN, $this->context->getCurrentBranch()); + $variable = new Variable($expr->name, $value, $type, $this->context->getCurrentBranch()); $this->context->addVariable($variable); } @@ -485,7 +487,7 @@ protected function passPropertyFetch(Node\Expr\PropertyFetch $expr) } return new CompiledExpression(CompiledExpression::UNKNOWN); - } elseif (!$scopeExpression->canBeObject()) { + } elseif ($scopeExpression->canBeObject()) { return new CompiledExpression(CompiledExpression::UNKNOWN); } diff --git a/src/Compiler/Statement/ForeachSt.php b/src/Compiler/Statement/ForeachSt.php index fa2a1f33..463a08a1 100644 --- a/src/Compiler/Statement/ForeachSt.php +++ b/src/Compiler/Statement/ForeachSt.php @@ -6,6 +6,7 @@ namespace PHPSA\Compiler\Statement; use PHPSA\Context; +use PHPSA\CompiledExpression; class ForeachSt extends AbstractCompiler { @@ -21,11 +22,11 @@ public function compile($stmt, Context $context) $context->getExpressionCompiler()->compile($stmt->expr); if ($stmt->keyVar) { - $context->getExpressionCompiler()->declareVariable($stmt->keyVar); + $context->getExpressionCompiler()->declareVariable($stmt->keyVar, null, CompiledExpression::MIXED); } if ($stmt->valueVar) { - $context->getExpressionCompiler()->declareVariable($stmt->valueVar); + $context->getExpressionCompiler()->declareVariable($stmt->valueVar, null, CompiledExpression::MIXED); } if (count($stmt->stmts) > 0) {