Skip to content

Commit

Permalink
Fix Bug ovr#107
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico committed Oct 3, 2016
1 parent a7bf656 commit 32b84ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/CompiledExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Compiler/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Compiler/Statement/ForeachSt.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace PHPSA\Compiler\Statement;

use PHPSA\Context;
use PHPSA\CompiledExpression;

class ForeachSt extends AbstractCompiler
{
Expand All @@ -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) {
Expand Down

0 comments on commit 32b84ee

Please sign in to comment.