Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for invoking closures #4501

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

faizanakram99
Copy link

@faizanakram99
Copy link
Author

@fabpot errors are unrelated

tests/TemplateTest.php Outdated Show resolved Hide resolved
@faizanakram99 faizanakram99 requested a review from fabpot December 12, 2024 14:22
tests/TemplateTest.php Outdated Show resolved Hide resolved
@fabpot
Copy link
Contributor

fabpot commented Dec 12, 2024

Last comment and I think we're good: can you add an item in the CHANGELOG file?

Copy link
Contributor

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I'd suggest opening an issue on php-src also, get_class_methods() should return __invoke to me (and other non static methods BTW).

- fixes twigphp#3848
- adds changelog entry
@faizanakram99
Copy link
Author

Last comment and I think we're good: can you add an item in the CHANGELOG file?

Done

@faizanakram99
Copy link
Author

LGTM I'd suggest opening an issue on php-src also, get_class_methods() should return __invoke to me (and other non static methods BTW).

Done php/php-src#17126

Copy link

@lowwa132 lowwa132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @faizanakram99

Copy link
Contributor

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PHP 8.0, we need to check that line 1742, we not calling isset($object->$item) for Closure as it does not work.

@@ -394,6 +394,9 @@ public static function getGetAttributeTests()
[true, ['foo' => 'bar'], $arrayAccess, 'vars', [], $anyType],
]);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add another test:

$tests[] = [true, 'closure called', fn (): string => 'closure called', '__invoke', [], $methodType];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support for closures or at least Closure::__invoke
4 participants