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

Downgrade attributes? #11

Open
leoloso opened this issue Sep 27, 2021 · 2 comments
Open

Downgrade attributes? #11

leoloso opened this issue Sep 27, 2021 · 2 comments

Comments

@leoloso
Copy link

leoloso commented Sep 27, 2021

I'm using Symfony DependencyInjection, which uses attribute #[Required] to call a function when creating a service.

When transpiling to PHP 7.1, #[Required] is still there.

This is a problem, attributes should be removed from PHP 7, since it introduces a new syntax.

But instead of removing it, could it be converted into something that doesn't break the application?

For instance, for DependencyInjection, transforming it to phpdoc /** @required */ works.

And for other cases? How to downgrade custom attributes?

@danog
Copy link
Contributor

danog commented Sep 27, 2021

The thing is, #[Required] is technically parsed as a comment on lower versions, so it's valid syntax even on PHP 7.1.
Another thing is the lack of Reflection classes to inspect the attributes on lower versions of PHP, which is a feature currently in the todo list.

@leoloso
Copy link
Author

leoloso commented Sep 27, 2021

Maybe can downgrade the common instances to phpdoc? For instance, could already convert #[Deprecated] to /** @deprecated */ (RFC)

And then, keep unknown ones as attributes? Possibly allow developers to downgrade them with custom logic via a custom hook (#10)?

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

No branches or pull requests

2 participants