Attribute¶
Attributes are machine readable options that may be added PHP code. Since PHP 8.0, they are accessible from PHP.
Attributes provide extra and customisable options for the PHP engine, static analysis tools and coders alike.
Attributes are a modern version of the phpdoc comment blocks.
Attributes are backward compatible: they can be used in any PHP version, and are ignored when not supported.
Attributes may or may not have a supporting class: attributes may be used for their semantic value, or with related code.
<?php
#[Attribute]
class X {}
?>
See also PHP Native Attributes, Using PHP Attributes instead of Annotations for Static Analysis, Unlocking the Power of Attributes in PHP, PHP Language Extensions, Playtime with PHP Attributes
Related : PHPdoc, PHP Native Attribute
Added in PHP 8.0