1.2.1334. Use PHP Attributes

This rule reports if PHP 8.0 attributes are in use.

Attributes look like special comments #[`... <https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list>`_]. They are linked to classes, traits, interfaces, enums, class constants, functions, methods, and parameters.

<?php

#[foo(4)]
class x {

}

?>

See also PHP RFC: Shorter Attribute Syntax, Attributes Amendements and Shorter Attribute Syntax Change.

1.2.1334.1. Specs

Short name

Php/UseAttributes

Rulesets

All, Appinfo, CE, Changed Behavior

Exakat since

2.1.6

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, Community Edition, Exakat Cloud