-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compatibility with named parameters and constructor property promotion #369
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should target master
, since it's not a bugfix.
Also, should docs be added regarding the new feature and how to migrate to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should target master
, since it's not a bugfix.
Also, should docs be added regarding the new feature and how to migrate to it?
|
||
/** | ||
* Marker interface for PHP7/PHP8 compatible support | ||
* for named arguments (and constructor property promotion). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should constructor property promotion really be mentioned here? You did not write a test for it, so I believe this means it does not really come into play here: it will work the same regardless of whether you use that feature or not.
…otion With PHP 8 the combination of named parameters and constructor property promotion will be very cool for the new Attributes feature, but also for Doctrine's Annotation feature. Especially if classes are to be used for both Attributes and Annotations, then the DocParser needs a compatible support for named parameters in annotation class constructors. For backwards compatibility this is done with a marker interface that uses a different instantiation logic than the current one. Currently all annotations properties are passed as a single array argument $values. This patch uses reflection to match annotation values to class constructor parameters. For PHP 8 the integration of named arguments with spread operator is used. A PHP 8 class that could be read using Doctrine Annotations would become: /** @annotation */ class Table implements NamedArgumentConstructorAnnotation { public function __construct( public string $name, public array $indexes = [] ) {} } /** @table(name="users") */ /** @table(name="users", indexes={"foo"}) */
c0177d9
to
c2af93a
Compare
@greg0ire right, rebased on master. I will document this as soon as we decide that this makes sense. |
With PHP 8 the combination of named parameters and constructor property
promotion will be very cool for the new Attributes feature, but also for
Doctrine's Annotation feature. Especially if classes are to be used
for both Attributes and Annotations, then the DocParser needs
a compatible support for named parameters in annotation class constructors.
For backwards compatibility this is done with a marker interface that
uses a different instantiation logic than the current one. Currently
all annotations properties are passed as a single array argument
$values.
This patch uses reflection to match annotation values to class
constructor parameters. For PHP 8 the integration of named arguments
with spread operator is used.
A PHP 8 class that could be read using Doctrine Annotations would
become: