1.2.699. Missing Attribute Attribute

A class that servers as attribute, should have the attribute #[`Attribute <https://www.php.net/attribute>`_].

While not strictly required, it is still recommended to create an actual class for every attribute.

<?php

namespace Example;

use Attribute;

#[Attribute]
class MyAttribute
{
}

#Missing the above attribute
class MyOtherAttribute
{
}

?>

See also Declaring Attribute Classes.

1.2.699.1. Suggestions

  • Add the Attribute attribute to those classes

1.2.699.2. Specs

Short name

Attributes/MissingAttributeAttribute

Rulesets

All, Analyze, Attributes, Changed Behavior, PHP recommendations

Exakat since

2.2.4

PHP Version

With PHP 8.0 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

attribute

Available in

Entreprise Edition, Exakat Cloud