PHP Attributes: Modern Metadata in Your Code
Since PHP 8, we’ve had attributes — a modern way to add metadata directly to classes, methods, or properties. Think of them like annotations in Java or decorators in Python. What are Attributes? Attributes let you “tag” parts of your code with extra information. Frameworks or libraries can then read these tags at runtime and act on them. Example: #[Route('/home', methods: ['GET'])] class HomeController { // ... } Here, the Route attribute describes how this controller should be exposed. ...