-
Notifications
You must be signed in to change notification settings - Fork 236
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
Possible BC break in nested array annotations with @NestedAnnotation #418
Comments
Well, doctrine/annotations has 3 ways to instantiate annotations. Among those, only Note that your "userland workaround" produces a different API. It gives an array (with 2 items) as one argument, not 2 arguments.
I don't understand which BC break you are talking about. The existing behavior when |
the unfortunate thing is that doctrine/annotations silently ignores invalid usages of old annotations (using multiple positional arguments while only the last one was kept) instead of reporting it loudly. |
Here is the PR in open-source project contributte/apitte#165 When we remove the |
@TomasVotruba as I said, when you use n |
I know. That's handled like this: https://github.com/apitte/core/blob/5fae3d46984b70e1ee908a4aa6b228e142d88bdb/src/Annotation/Controller/RequestParameters.php#L20-L32 |
Basically question is: how can I preserve original behavior (2 items found in any situation) with adding |
you mean, allowing people to misuse the annotations where all nested positional annotations except the last one are silently lost ? Well, add a variadic constructor argument and discard all values except the last one... |
No, I mean keeping the original behavior (2 items) that would not be influenced by the If it's not possible, then I'll come up with fixer rule, no troubles :) |
ah indeed. I misread the code for the old way. In case of multiple positional arguments, it does not ignore them. It turns it into an array value instead (which makes the signature quite confusing as that |
Thanks for patience with me. That's exactly what I meant the whole time 👍 I don't understanda how should I fix it. I thought this snippet already handles it, but it does not: Could you explain me in real PHP code example what should I do with my annotation to make it work? |
@TomasVotruba your constructor only uses the first argument. So it does not handle being called as This code you linked deals with the weird signature provided by the old doctrine/annotations instantiator. As said before, if you want to migrate to |
I see. But how can I handle |
well, using |
It will not be as easy. When I use: public function __construct(...$parameters) I get this error: -- FAILED: DI\Loader\DoctrineAnnotationLoader for combination of attribute and annotations | MixedAttributeAnnotationLoader.phpt
Exited with error code 255 (expected 0)
ReflectionException: Internal error: Failed to retrieve the default value
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(617)
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(617) ReflectionParameter->getDefaultValue()
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(824) Doctrine\Common\Annotations\DocParser->collectAnnotationMetadata()
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(719) Doctrine\Common\Annotations\DocParser->Annotation() |
Using /**
* @param RequestParameter[] $parameters
*/
public function __construct()
{
$parameters = func_get_args(); -- FAILED: DI\Loader\DoctrineAnnotationLoader for combination of attribute and annotations | MixedAttributeAnnotationLoader.phpt
Exited with error code 255 (expected 0)
Doctrine\Common\Annotations\AnnotationException: [Creation Error] The annotation @RequestParameters declared on method Tests\Fixtures\Controllers\Mixed\PathAndRequestParamsController::run() does not accept any values, but got {"value":[{},{}]}.
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php(52)
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(1005) Doctrine\Common\Annotations\AnnotationException::creationError()
in var/www/core-1/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(719) Doctrine\Common\Annotations\DocParser->Annotation() |
In the end I've made a CS fixer that fixes this is in a few seconds :) deprecated-packages/symplify#3396 @stof Thank you for your consultation and proposed solutions. I was really lost in the start and you helped me to orientate better in the issue and choose the most effective way to go 🙇 |
Hi everyone!
Thanks for adding #402 , it's a life saver with PHP 8 and migration to attributes 👏
I've been exploring one weird bug we had in our code base:
What is the problem?
This code returns 1 or 2
NestedAnnotation
annitatons, depending if@NamedArgumentConstructor
is used aboveNestedAnnotation
.It should fixed in userland like this:
But at the moment it's a BC break, only first annotation is included. I think this BC breaks should not happen and there should be always 2 instances of
NestedAnnotation
regardless use of@NamedArgumentConstructor
.I'm looking into it 🙂 Any feedback appreciated 👍
The text was updated successfully, but these errors were encountered: