Type hinting with doctrine: Is the type attribute still required on @ORM\Column annotation when using PHP 7.4 with type hints?

Viewed 1250

The doctrine documentation for @ORM\Column says that the type-attribute is required. Does that still hold with PHP 7.4? With type hints directly in PHP I feel that the type-attribute in the annotation is redundant. Is there a way to not provide the type-attribute and make doctrine infer it from the PHP type hints?

Example:

Instead of using this code

class Client
{
    /** @ORM\Column(name="code"   , type="string" , length=20    , unique=true) */ private string $code;
    /** @ORM\Column(name="moduleX", type="boolean", nullable=true             ) */ private ?bool $moduleX;
    // [...]

I'd like to write the following:

class Client
{
    /** @ORM\Column(name="code"   , length=20, unique=true) */ private string $code;
    /** @ORM\Column(name="moduleX",                       ) */ private ?bool $moduleX;
    // [...]

If not, is that feature in discussion - or is there a way to suggest it?

1 Answers

Doctrine types is conversion between PHP and SQL types. Even simple PHP types like string can be VARCHAR, DECIMAL, or CLOB in the database.

And the type hint can be an object too:

private UuidInterface $id;

How to store this in the database? String, binary, integer?

Doctrine doesn't know about your application business logic so I think reflection is not a good replacement for annotation.

Related