I've recently come across a little niggle regarding annotations in Symfony (not sure if this is a pure PHP thing as well).
The new route annotation looks like this:
#[Route('route', name: 'route_name')]
When I want @throws
the same type of annotation, I can't find any way to replace the old type that looks like this:
/** * @throws Exception */
So I want new types of comments, even @throws
P粉0769873862024-03-28 09:16:53
The main idea behind attributes is to attach static metadata to our code (methods, properties, etc.). This metadata often includes concepts such as "configuration". In your example, this property sets a path to your frame. With principles, you can build your entities. A few years ago, there were no properties, so developers used annotations to declare them. PHP8 allows us to use properties. Let's avoid using annotation (@Route).
TheThrow tag does not set anything in your application. This exception can only be thrown by your code.
/** * @throws Exception //this line has no impact on your code */ #[Route('route', name: 'route_name')] //this line has an impact by setting up your routes public myAction() { throw new Exception('foo'); // This line have an impact on your code }
This is information for developers (and valuable IDEs) to help us understand our code. Therefore, the @Throw tag does not have the attribute version. @Throw tags are "only" documentation, PHPDoc, comments :) Your code should have a mix of comments in comments and properties