Closed
Description
Description
There is ongoing work about deprecating the usage of annotations:
- [Routing] Deprecate annotations in favor of attributes #49358
- [DependencyInjection] deprecate the
@required
annotation #48990
I didn't see a general discussion about this subject, so I created this issue to rai 5E2F se the question:
Should some or all annotations be deprecated in 6.3 and removed in 7.0?
Attributes are natively supported with Symfony 6.3+, because it requires PHP ≥ 8.1 and attributes were added in PHP 8.0. While annotations require to install doctrine/annotations
.
On a side note, PHPUnit 10 allow to use attributes instead of annotations: sebastianbergmann/phpunit#4502
Example
- /**
- * @required
- */
+ #[\Symfony\Contracts\Service\Attribute\Required]
public function setFoo(Foo $foo)
{
// should be called
}