PHP theorytheory 0/50 · 0%
Fundamentals · medium

24. Attributes

Structured metadata for code.

Attributes, introduced in PHP 8.0, provide a native syntax for adding metadata to classes, methods, and properties using #[AttributeName] syntax, replacing docblock annotations. They are read at runtime via the Reflection API.

Frameworks use attributes for routing, validation, dependency injection, and ORM mapping, e.g. #[Route('/users')] on a controller method.

Check your understanding

  1. 1. What syntax denotes a PHP attribute?

  2. 2. How are attributes typically inspected at runtime?