4 ms·
What is this? class User { /** * @Assert\All({ * @Assert\NotNull, * @Assert\Length(min=5) * }) */ public string $
by EGreg 5y ago
What is this?
class User
{
/**
* @Assert\All({
* @Assert\NotNull,
* @Assert\Length(min=5)
* })
*/
public string $name = '';
}
PHP 8.1
class User
{
#[\Assert\All(
new \Assert\NotNull,
new \Assert\Length(min: 6))
]
public string $name = '';
}
- codazoda 5y agoJust going to link to this from earlier today. https://front-line-php.com/cheat-sheet https://front-line-php.com/cheat-sheet It’s covered under “Attributes”.
- hu3 5y agoThese are attributes which add metadata that can be programatically acessed by applications and tooling. That piece of code is about data validation. See more at https://www.php.net/manual/en/language.attributes.overview.php https://www.php.net/manual/en/language.attributes.overview.p...
- deleted 5y ago[deleted]
- exitheone 5y agoAn annotation syntax no outside of doc strings. Something PHP desperately needed. Very similar to Java annotations.
- pluc 5y agoDoctrine ORM uses Annotations to label SQL data, it's a pretty good example of Annotations in action: https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/annotations-reference.html https://www.doctrine-project.org/projects/doctrine-orm/en/2....