Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Not An Attribute

<?php

class MyNotAnAttributeClass {
    public function __construct(public string $value) {}
}

#[MyNotAnAttributeClass('test')]
class MyClass {}

You can use any class as an attribute, even if it is not explicitly marked with the #[Attribute] meta-attribute. While it is recommended to use #[Attribute] to make a class explicitly an attribute, it is not strictly required. PHP will still treat the class as an attribute if you use it as one, as long as you do not try to instantiate it via reflection. This means you can define a class without the #[Attribute] meta-attribute and still use it as an attribute in your code.

See Also

PHP Features

Last updated: 22 October 2026