Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Predefined AttributesAttribute::__construct>
^Predefined AttributesLast updated: Mon, 26 Oct 2026

The Attribute attribute

(PHP 8)

Introduction

Attributes offer the ability to add structured, machine-readable metadata information on declarations in code: Classes, methods, functions, parameters, properties and class constants can be the target of an attribute. The metadata defined by attributes can then be inspected at runtime using the Reflection APIs. Attributes could therefore be thought of as a configuration language embedded directly into code.

Class synopsis

#[\Attribute(\Attribute::TARGET_CLASS)]
final class Attribute {
/* Constants */
/* Properties */
public int $flags;
/* Methods */
public function __construct(int $flags = Attribute::TARGET_ALL)
}

Properties

flags

Changelog

Version Description
8.5.0 Added Attribute::TARGET_CONSTANT. Applying #[\Attribute] to an abstract class, enum, interface, or trait now triggers a compile-time error (previously it was only reported at runtime when ReflectionAttribute::newInstance() was called).

Table of Contents


<Predefined AttributesAttribute::__construct>
^Predefined AttributesLast updated: Mon, 26 Oct 2026