Using class constants in Doctrine annotations
Published on 2019-11-07 • Modified on 2022-04-27
[Edit 2022-04-27] I use PHP 8 attributes now, click on the "read the doc" link to see a relevant example. 🙃
This is a small trick to avoid putting raw values in your Doctrine annotations. For example, it is useful when you have a length constraint that can be shared among several fields and entities. You can also use these constants to create your form type constraints. Note that they must be public or you will get an error.
/**
* Allow to force the highlight class of the snippet main code if autodetection
* doesn't work correctly.
*/
#[ORM\Column(type: 'string', length: self::VARCHAR_MAX, nullable: true)]
protected ?string $highlightClass = null;
More on Stackoverflow Read the doc Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉