diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 240553f93..2cea1bdbf 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -239,12 +239,12 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) { array_pop($parameters); } else { - $callableName = $r->name; - if ($r->getDeclaringClass()) { - $callableName = $r->getDeclaringClass()->name.'::'.$callableName; - } - - throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); + throw new LogicException(sprintf( + 'The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', + $r instanceof ReflectionMethod ? $r->getDeclaringClass()->name.'::'.$r->name : $r->name, + $this->getAttribute('type'), + $this->getAttribute('name') + )); } } diff --git a/test/Twig/Tests/Node/Expression/CallTest.php b/test/Twig/Tests/Node/Expression/CallTest.php index 43afcd292..28c8148ff 100644 --- a/test/Twig/Tests/Node/Expression/CallTest.php +++ b/test/Twig/Tests/Node/Expression/CallTest.php @@ -105,6 +105,26 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase public function customFunctionWithArbitraryArguments() { } + + /** + * @expectedException LogicException + * @expectedExceptionMessageRegExp #^The last parameter of "custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$# + */ + public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true)); + $node->getArguments('custom_Twig_Tests_Node_Expression_CallTest_function', array()); + } + + /** + * @expectedException LogicException + * @expectedExceptionMessageRegExp #^The last parameter of "CallableTestClass\:\:__invoke" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$# + */ + public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true)); + $node->getArguments(new CallableTestClass(), array()); + } } class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call @@ -114,3 +134,14 @@ class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call return parent::getArguments($callable, $arguments); } } + +class CallableTestClass +{ + public function __invoke($required) + { + } +} + +function custom_Twig_Tests_Node_Expression_CallTest_function($required) +{ +}