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 Function Attributes support #46

Merged
merged 3 commits into from
May 16, 2022
Merged

Conversation

nunomaduro
Copy link
Member

This pull request adds function attributes support to serialisable closures:

#[Attribute(Attribute::TARGET_FUNCTION)]
class MyAttribute
{
    // ..
}

$closure = #[MyAttribute('My attribute argument')] function () {
    return true;
};

$closure = unserialize(serialize($closure))->getClosure();

// Before this pull request:
dd(new ReflectionFunction($closure))->getAttributes());
// []

// After this pull request:
dd(new ReflectionFunction($closure))->getAttributes());
// [['name' => 'MyAttribute', 'arguments' => ['My attribute argument']]]

@nunomaduro nunomaduro requested a review from taylorotwell May 16, 2022 09:47
@morloderex
Copy link
Contributor

morloderex commented May 16, 2022

@nunomaduro At first glance this looks great. But I don't see tests and handling for attributes which uses named arguments?

@nunomaduro
Copy link
Member Author

@morloderex Thanks for bringing that to my attention. It's fixed.

@taylorotwell taylorotwell merged commit 3cdb166 into master May 16, 2022
@taylorotwell taylorotwell deleted the feat/function-attributes branch May 16, 2022 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants