🌐
PHP
php.net › manual › en › language.attributes.overview.php
PHP: Attributes overview - Manual
PHP attributes provide structured, machine-readable metadata for classes, methods, functions, parameters, properties, and constants. They can be inspected at runtime via the Reflection API, enabling dynamic behavior without modifying code.
🌐
Stitcher
stitcher.io › blog › attributes-in-php-8
PHP 8: Attributes | stitcher.io
A close look at attributes, also known as annotations; in PHP 8
Discussions

Using PHP Attributes instead of Annotations for Static Analysis
I dont really see an big advantage of using attributes for this over phpdoc: The article says: "but the main reason is that comments were created so that you could add information about your code, not as a mean of defining the properties of the code." But I think that is exactly the case here. These type information are just additional information to provide some context for the users and maybe static analysis tools. These are purely informational and do not change any behavior of the code or let the PHP interpreter do anything differently. And from a technical point of view I dont think its that complicated to parse the docblocks hints, especially in a context of static analysis tools where performance is not so important. Another thing I think is a missed opportuinity: If you already use attributes to specify the type of function parameters further, then you should put these attribute directly on the parameter itself (with Attribute::TARGET_PARAMETER ) and not on the function level. That way the connection of the parameter with the type attribute is much clearer and can also be parsed more easily. More on reddit.com
🌐 r/PHP
18
20
May 8, 2024
What are peoples thoughts/feelings regarding PHP attributes?
Call me an idiot, but for me I still don't really "get it". I mean, I understand the syntax and all that, and PHPStorm has added a few of them here and there for me (mainly ArrayShape which can be mildly useful) but I just don't really understand the killer feature/purpose of them. More on reddit.com
🌐 r/PHP
53
21
December 16, 2021
How do PHP attributes work?
You use Reflection to get information about a class structure. Attributes are their own class that get loaded when you access the attribute with reflection. It’s a way to have separate logic that conveys additional information in a composable manner. Routes are a common example. A controller method doesn’t have anything that ties it to incoming http requests. Adding an attribute allows you to configure that method and associate it with other information like a path and http method. You’re effectively applying meta data that has an ability to contain logic. More on reddit.com
🌐 r/PHP
10
0
June 7, 2024
Attributes in PHP 8 - A detailed guide
I like this feature, but I can’t stand this syntax. It reminds me of !!ERROR!! Or #WARNIG# I get alarmed and slightly frightened when I see it. I do wish it was @@ or @: I am already use to docblocks and it would be a nice transition. More on reddit.com
🌐 r/PHP
33
46
May 30, 2020
🌐
Honeybadger
honeybadger.io › blog › php-attributes-guide
A guide to PHP attributes - Honeybadger Developer Blog
June 18, 2024 - They enable you to add machine-readable, structured metadata to your code. They can be applied to classes, class methods, functions, anonymous functions, properties, and constants.
🌐
DEV Community
dev.to › arasosman › php-attributes-in-laravel-complete-guide-2025-3bh8
PHP Attributes in Laravel: Complete Guide 2025 - DEV Community
August 7, 2025 - The traditional approach of using ... solution. PHP attributes allow you to attach structured metadata directly to classes, methods, properties, and parameters using a clean, declarative syntax....
🌐
PHP.Watch
php.watch › versions › 8.0 › attributes
Attributes - PHP 8.0 • PHP.Watch
One of the biggest new changes in PHP 8 is the Attributes support. Attributes help to add meta-data to PHP functions, parameters, classes, class methods, constants, properties, closures, and even anonymous classes.
🌐
Medium
medium.com › @valerio_27709 › php-attributes-how-to-use-php-attributes-and-create-custom-attribute-classes-fast-tips-f073549d481c
PHP Attributes: how to use PHP Attributes and create custom attribute classes — Fast Tips | by Valerio Barbera | Medium
August 23, 2024 - As mentioned before adding the attribute to the property have no impact during execution. But we can now retrive this information using reflection to take some action eventually. The most used PHP frameworks like Symfony and Laravel are already adopting attributes to basically replace “Annotations”. In Symfony 5.2 or greater you are able to declare a controller and wire it up to a route using attributes:
🌐
WooCommerce
woocommerce.github.io › woocommerce-rest-api-docs
WooCommerce REST API Documentation - WP REST API v3
The auth endpoint will send the API Keys in JSON format to the callback_url, so it's important to remember that some languages such as PHP will not display it inside the $_POST global variable, in PHP you can access it using $HTTP_RAW_POST_DATA (for old PHP versions) or file_get_contents('php://input');.
Find elsewhere
🌐
PHP.Watch
php.watch › articles › php-attributes
Attributes in PHP 8 • PHP.Watch
May 29, 2020 - Instead of writing a separate definition in the form of an XML schema or a JSON schema, Attributes provide an easy and manageable way to organize this meta-data. Many languages have similar features to PHP Attributes.
🌐
Reddit
reddit.com › r/php › using php attributes instead of annotations for static analysis
r/PHP on Reddit: Using PHP Attributes instead of Annotations for Static Analysis
May 8, 2024 - That way the connection of the parameter with the type attribute is much clearer and can also be parsed more easily. ... But I think that is exactly the case here. These type information are just additional information to provide some context for the users and maybe static analysis tools. These are purely informational and do not change any behavior of the code or let the PHP interpreter do anything else.
🌐
Medium
itsimiro.medium.com › unlocking-the-power-of-attributes-in-php-a6af57225bbf
Unlocking the Power of Attributes in PHP | by itsimiro | Medium
May 22, 2024 - PHP attributes are a robust and flexible way to improve your code by embedding metadata directly into it. They improve readability, centralize configuration, provide type safety, reduce boilerplate, improve integration with frameworks, and increase ...
🌐
Laravel News
laravel-news.com › home › laravel packages › a clean api for reading php attributes
A Clean API for Reading PHP Attributes - Laravel News
1 month ago - PHP 8.0 introduced attributes — a first-class way to add structured metadata to classes, methods, properties, and more. But reading them programmatically with the native reflection API is verbose and repetitive.
🌐
DEV Community
dev.to › xxzeroxx › php-8-news-attributes-3
PHP 8 News: Attributes - DEV Community
February 24, 2024 - Attributes provide a way to add metadata to classes, methods, functions, properties, and parameters in your PHP code.
🌐
DEV Community
dev.to › icolomina › using-php-attributes-easily-2fpo
Using PHP attributes easily - DEV Community
November 11, 2025 - PHP attributes are a new feature included in the last php 8 version which allow us to easily add... Tagged with php, attributes.
🌐
Jump24
jump24.co.uk › journal › playtime-with-php-attributes
PHP 8 Attributes Tutorial | Metadata Programming Guide
Using a a trait here means we can stub out a private handle method that we expect to be overridden by the parent class. This is quite nice as we can't enforce this with an interface or abstract class in PHP as they don’t support private methods. Furthermore PHP 8.3 introduced the #[\Override] Attribute which we can add to the trait method to ensure it is overridden:
🌐
Reddit
reddit.com › r/php › what are peoples thoughts/feelings regarding php attributes?
r/PHP on Reddit: What are peoples thoughts/feelings regarding PHP attributes?
December 16, 2021 -

With the release of PHP 8.0 came attributes, the native answer to the docblock annotations we'd been using up until then.

If you aren't familiar with them, here's the PHP docs for it https://www.php.net/manual/en/language.attributes.overview.php and here's the stitcher article by our very own u/brendt_gd https://stitcher.io/blog/attributes-in-php-8

As a big fan of Java and other, far stricter languages, I've seen the power of annotations/attributes, and it's something I'm excited about.

I think because of how they work, and because of the somewhat slow and bulky nature of reflection, they aren't a huge viable option for widespread use. I'm experimenting with a way to make them more viable, and so far so good, but I wanted to get some opinions on them.

What do you think about attributes? How do you feel about them? Do you see their value? Do you not care? Are you not sure what they are?

Top answer
1 of 12
15
I've seen the power of annotations/attributes Annotations are the Java solution to needing mixins. Pure inheritance, even with interfaces, is brittle and lacks expressiveness for any non-trivial application. Java picked out a PARC project and everyone nodded their heads because it was backward compatible and it came from PARC; it must be great right? @Spring is both the proof and the poster child for what is to come. In Java, depending on the libraries you are using, you may be faced with the unenviable position of having to worry about annotations added somewhere in the codebase that has an effect on an application in part or in whole. Who knows? You have to read the whole thing to find out where your exceptions are going...is it captured by some annotation on the stack, or passed by to some class that has a @RestControllerAdvice annotation? Not to mention the effect it has on weakening your testing methodology (in execution time, complexity, and reliability) for testing your actual application. How do you setup for @Component? Have to read that code to understand the implications. Do not put user code generation in the runtime. Integrating an additional problemspace on complex software is yet another step in the slow decline. Aspects were a cute short-term solution to implement runtime code generation that has now turned into runtime composition (or concatenation ) and has had the same result that Attributes will.
2 of 12
12
Call me an idiot, but for me I still don't really "get it". I mean, I understand the syntax and all that, and PHPStorm has added a few of them here and there for me (mainly ArrayShape which can be mildly useful) but I just don't really understand the killer feature/purpose of them.
🌐
Medium
medium.com › @arifhossen.dev › how-to-use-attributes-in-php-a-modern-approach-to-metadata-26206e32f8e9
How to use Attributes in PHP: A Modern Approach to Metadata | by Arif Hossen | Medium
December 27, 2024 - Consider performance impact when using reflection-heavy attribute implementations. ... PHP Attributes modernize code organization and enhance maintainability. Start with framework-provided attributes, then create custom ones as needed.
🌐
Reddit
reddit.com › r/php › how do php attributes work?
How do PHP attributes work? : r/PHP
June 7, 2024 - Please respect r/php's rules. ... Sorry, this post was deleted by the person who originally posted it. Share ... You use Reflection to get information about a class structure. Attributes are their own class that get loaded when you access the attribute with reflection.
🌐
dailycomputerscience
dailycomputerscience.com › post › attributes-in-php-8
Attributes in PHP 8
November 10, 2024 - PHP 8 introduced a host of new ... programming languages). Attributes offer a powerful way to add metadata to classes, methods, properties, and functions without altering their actual code....