Attributes: Introduction

Attributes are a holder of metadata for any reflectable piece of code. This includes functions, classes, interfaces, traits, etc.

Except for a few special attributes, attributes are a purely syntactic entity. They lend themselves to tooling to accomplish tasks. For example, you can have documentation-based attributes, the contents of which are extracted by reflection.


namespace Hack\UserDocumentation\Attributes\Intro\Examples\Simple;

<<ClassOwner("Joel Marcey"), Description("This class does nothing")>>
class Simple {}

function get_attributes(): void {
  $rc = new \ReflectionClass(

array(1) {
  string(23) "This class does nothing"

Special Attributes

Some attributes have special meaning to both the Hack typechecker and HHVM. Here are the most common and useful ones:

There are a few much less common special attributes as well.