mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 04:27:00 +00:00
Fixes CallExpression::reflectCallable() throwing TypeError
This commit is contained in:
@@ -290,7 +290,12 @@ abstract class CallExpression extends AbstractExpression
|
||||
}
|
||||
|
||||
$checkVisibility = $callable instanceof \Closure;
|
||||
$r = new \ReflectionFunction(\Closure::fromCallable($callable));
|
||||
try {
|
||||
$closure = \Closure::fromCallable($callable);
|
||||
} catch (\TypeError $e) {
|
||||
throw new \LogicException(sprintf('Callback for %s "%s" is not callable in the current scope.', $this->getAttribute('type'), $this->getAttribute('name')), 0, $e);
|
||||
}
|
||||
$r = new \ReflectionFunction($closure);
|
||||
|
||||
if (false !== strpos($r->name, '{closure}')) {
|
||||
return $this->reflector = [$r, $callable, 'Closure'];
|
||||
|
||||
@@ -94,6 +94,15 @@ class CallTest extends TestCase
|
||||
$this->getArguments($node, [[$this, 'customFunctionWithArbitraryArguments'], []]);
|
||||
}
|
||||
|
||||
public function testGetArgumentsWithInvalidCallable()
|
||||
{
|
||||
// see https://github.com/twigphp/Twig/issues/3708
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage('Callback for function "foo" is not callable in the current scope.');
|
||||
$node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
|
||||
$this->getArguments($node, ['<not-a-callable>', []]);
|
||||
}
|
||||
|
||||
public static function customStaticFunction($arg1, $arg2 = 'default', $arg3 = [])
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user