PHP/Symfony annotation for Throw tag
P粉464082061
P粉464082061 2024-03-27 17:50:27
0
1
394

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粉464082061
P粉464082061

reply all(1)
P粉076987386

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).

The

Throw 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template