Skip to content

Commit

Permalink
don't call isset(closure->__invoke)
Browse files Browse the repository at this point in the history
- adds another test
  • Loading branch information
faizanakram99 committed Dec 12, 2024
1 parent 535a112 commit 85345e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,10 @@ public static function getAttribute(Environment $env, Source $source, $object, $

static $propertyCheckers = [];

if ($object instanceof \Closure && '__invoke' === $item) {
return $isDefinedTest ? true : $object();
}

if (isset($object->$item)
|| ($propertyCheckers[$object::class][$item] ??= self::getPropertyChecker($object::class, $item))($object, $item)
) {
Expand Down
1 change: 1 addition & 0 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public static function getGetAttributeTests()

// test for Closure::__invoke()
$tests[] = [true, 'closure called', fn (): string => 'closure called', '__invoke', [], $anyType];
$tests[] = [true, 'closure called', fn (): string => 'closure called', '__invoke', [], $methodType];

// tests when input is not an array or object
$tests = array_merge($tests, [
Expand Down

0 comments on commit 85345e4

Please sign in to comment.