This is what I would like to use:
#[ORM\Column(type: "string")]
instead of this:
/**
 *  @ORM\Column(type="string")
 */
But I'm getting this error:
(error: Class 'Column' is not annotated with 'Attribute' )
Is it because Doctrine does not support it yet, or am I missing something?
As @Seb33300 says, yes, it's now possible in Doctrine ORM 2.9. But for Symfony you need to do a little bit more than that. Here is a full list of steps to upgrade:
Upgrade Doctrine ORM: "doctrine/orm": "^2.9".
Upgrade Doctrine Bundle: "doctrine/doctrine-bundle": "^2.4".
Set doctrine.orm.mappings.App.type: attribute (by default it's set to annotation):
# config/packages/doctrine.yaml
doctrine:
  orm:
    mappings:
      App:
        type: attribute
Apply similar changes to your entities:
--- Dummy.php.old     Mon Jun 07 00:00:00 2021
+++ Dummy.php         Mon Jun 07 00:00:00 2021
@@ -7,15 +7,11 @@
 use App\Repository\DummyRepository;
 use Doctrine\ORM\Mapping as ORM;
-/**
- * @ORM\Entity(repositoryClass = DummyRepository::class)
- */
+#[ORM\Entity(repositoryClass: DummyRepository::class)]
 class Dummy
 {
-    /**
-     * @ORM\Id
-     * @ORM\GeneratedValue
-     * @ORM\Column(type = 'integer')
-     */
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column(type: 'integer')]
     private $id;
 }
EDIT: Doctrine 2.9 is now released with PHP 8 attributes support!
PHP 8 annotations have been merged in Doctrine ORM 2.9.x branch which is not released yet:
https://github.com/doctrine/orm/pull/8266
Here is the documentation reference related to this feature: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/attributes-reference.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With