Skip to content

Commit c8b65ae

Browse files
committed
[ExpressionLanguage] throws an exception on calling uncallable method
1 parent 9c796b4 commit c8b65ae

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ public function evaluate($functions, $values)
7777
if (!is_object($obj)) {
7878
throw new \RuntimeException('Unable to get a property on a non-object.');
7979
}
80+
if (!is_callable($toCall = array($obj, $this->nodes['attribute']->attributes['value']))) {
81+
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], get_class($obj)));
82+
}
8083

81-
return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['value']), $this->nodes['arguments']->evaluate($functions, $values));
84+
return call_user_func_array($toCall, $this->nodes['arguments']->evaluate($functions, $values));
8285

8386
case self::ARRAY_CALL:
8487
$array = $this->nodes['node']->evaluate($functions, $values);

src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ public function testRegisterAfterEval($registerCallback)
163163
$registerCallback($el);
164164
}
165165

166+
/**
167+
* @expectedException \RuntimeException
168+
* @expectedExceptionMessageRegExp /Unable to call method "\w+" of object "\w+"./
169+
*/
170+
public function testCallBadCallable()
171+
{
172+
$el = new ExpressionLanguage();
173+
$el->evaluate('foo.myfunction()', array('foo' => new \stdClass()));
174+
}
175+
166176
/**
167177
* @dataProvider getRegisterCallbacks
168178
* @expectedException \LogicException

0 commit comments

Comments
 (0)