Skip to content

Commit

Permalink
fix foo[index]
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris authored and fabpot committed Jan 17, 2014
1 parent ac45678 commit d090b76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php
Expand Up @@ -81,12 +81,12 @@ public function evaluate($functions, $values)
return call_user_func_array(array($obj, $this->nodes['attribute']->evaluate($functions, $values)), $this->nodes['arguments']->evaluate($functions, $values));

case self::ARRAY_CALL:
$values = $this->nodes['node']->evaluate($functions, $values);
if (!is_array($values) && !$values instanceof \ArrayAccess) {
$array = $this->nodes['node']->evaluate($functions, $values);
if (!is_array($array) && !$array instanceof \ArrayAccess) {
throw new \RuntimeException('Unable to get an item on a non-array.');
}

return $values[$this->nodes['attribute']->evaluate($functions, $values)];
return $array[$this->nodes['attribute']->evaluate($functions, $values)];
}
}
}
Expand Up @@ -27,6 +27,7 @@ public function getEvaluateData()
array('bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), array('foo' => new Obj())),

array('baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), array('foo' => new Obj())),
array('a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), array('foo' => array('b' => 'a', 'b'), 'index' => 'b')),
);
}

Expand All @@ -39,6 +40,7 @@ public function getCompileData()
array('$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), array('foo' => new Obj())),

array('$foo->foo(array("b" => "a", 0 => "b"))', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), array('foo' => new Obj())),
array('$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)),
);
}

Expand Down

0 comments on commit d090b76

Please sign in to comment.