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
Incorrect class path for property when using traits #2467
Comments
Hi @danaki, This is a known issue. The problem here is that php's reflection library doesn't provide the information. It is kind of hard to solve this without much performance impact. The issue is tracked in the type-resolver component which should cover these use cases. But we still don't know exactly how. Thanks for reaching out. And providing so much information to reproduce this issue. |
I think performance doesn't matter because reflection can't be fast per se. Can you please at least make it throw an exception if you can't fix it right now because this behavior leads to erroneous situation. I've spent hours debugging API Platform/Symfony internals to find out this bug belongs to phpdocumentor without knowing this project even exists. |
The problem with throwing an exception is that we don't know at runtime that your trait exists, if we would know it, we could have returned the correct type. I'm sorry to hear that you had to spend so much time on this. Since we had contact with both the Symfony team and the API platform team about this particular issue, they should have mentioned this in their docs. You might want to open an issue for that :-) |
Is there a chance php core developers will fix this reflection issue in an upcoming release? Are they aware? |
I don't know if the core developers are aware. If they are it would probably not be a minor fix. Because of way that traits work. I don't know if they do exist at runtime. Sometimes php has its limits. Thing you just run into one. Traits are dark magic, also in the core. As far as I know. Pretty useful for developers, but they don't have a meaning at runtime. |
IIRC, traits are literally automated copy-paste. From what I understand, upon interpreting a class the contents of a trait are copy-pasted into that class and all references to that trait are gone. |
When class A uses trait B and that trait defines a property like so:
then
$commissionType
resolved asApp\Entity\CommissionType
not\App\Entity\Enum\CommissionType
(please refer to src/bug.php from the repository reproducing bug: https://github.com/danaki/phpdocumentor-bugRun:
Output:
\App\Entity\CommissionType
Should be:
\App\Entity\Enum\CommissionType
Versions of phpDocumentor components are fixed to required by Symfony 5 and latest API Platform. May be this bug already fixed in recent releases of phpDocumentor then API Platform should be upgraded.
The text was updated successfully, but these errors were encountered: