Class attributes case examples?


I am wondering for quite some time what the use of attributes actually is. I never needed them or saw a use case for this, but this could simply be the case because I never was learned to use them.
I searched the docs and found this:$attributes
It is explained very well what they are and how to use them. But I cannot find in the text why I should use them (that might not be the goal of the docs, so that’s not a problem)

So, I’m super curious, why do you use attributes? I’m very interested in real use cases!


In the plugin I use them for deprecation and for making items invisible from auto complete.

As the doc page you linked describes, you might want to use the special attributes to deprecate or hide items.

Otherwise you’d only use attributes if you are also using Introspection. One example: Say you’re making a object-relational framework to interface classes with a database. You could use an attribute on the class that tells it the name of the database table it refers to and then look at the attribute using introspection at run-time so that the class knows which table to query.

It is a good question because you could generally use a constant in much the same way. It just so happens to be the way to signal certain information to the IDE.