Open goetas opened 6 years ago
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Not really fun of it, I prefer explicit types.
Closing. If someone has valid points, i'm ready to re-consider it.
:-1: for closing
It's a great usability feature.
I was about to make the same feature request as this. @var string
seems just as explicit as @Serializer\Type("string")
, and @var
has the advantage that many different tools will read it. As it is I always put both annotations in. Most of the time we want the types set by the deserialise function to match types understood by IDEs, static analysis tools and documentation generating tools.
To make this more useful it would be good to understand use
statements for namespace resolution, and if #1090 is implemented nullable types.
Explicit @Type
will be even more annoying with PHP 7.4's typed properties.
When typed properties will land in PHP, the @var
annotation will be obsolete, then inferring the type from the property reflection will make perfectly sense.
In that case will be happy to accept a PR with that feature.
Even in 7.4 @var
won't be entirely obsolete, because people use it with types that are not understood by the PHP engine - e.g. @var array<\DateTimeInterface>
, @var int|string
, @var mixed
etc. The first of these is also supported by the existing @Type annotation.
But I might be interested in making that PR for 7.4 typed properties support some time a bit nearer to 7.4 release date.
@goetas Not really sure what you mean by your comment - @var
is already substituing absense of the typed properties and therefore supporting it makes sense already.
Also agreed with @bdsl - 7.4 won't make @var
obsolete by far - no union types, no generics.
Alright, I see that this feature has people that could use it. There are still many questions to be answered on how to implement it, some are:
should this be considered only when using the annotation driver?
No, Doctine Annotations are not a parser for phpDoc, they're not compatible.
if no, what happens for those that have the annotation driver disabled
N/A, this feature is independent on the annotation driver.
implemented as separate driver, sounds a good idea to me!
I'm not sure : is inferring types from PHP 7.4 types properties in the scope of this issue? Or is this covered elsewhere?
This has been implemented for both var annotations as well as property types in #1214 and #1192. So this can be closed.