phabel icon indicating copy to clipboard operation
phabel copied to clipboard

Downgrade attributes?

Open leoloso opened this issue 4 years ago • 2 comments

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?

leoloso avatar Sep 27 '21 10:09 leoloso

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.

danog avatar Sep 27 '21 13:09 danog

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)?

leoloso avatar Sep 27 '21 22:09 leoloso