-
-
Notifications
You must be signed in to change notification settings - Fork 702
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
Strange behavior dealing with PHP attributes and interfaces in dependencies #6688
Comments
I'm trying to investigate further, here is some additional debugging info:
|
I think I found a solution, can you please help me understanding what's happening? I published the fix to my reproducer repo: https://github.com/liarco/rector-issue/blob/2afdceb5ca71a1be5e644c63e2eeb9b1124b44e2/project/rector.php#L38-L41 When I first read the docs I tried fixing my problem with: // rector.php
// ...
$parameters->set(Option::AUTOLOAD_PATHS, [
__DIR__.'/vendor/autoload.php',
]);
// ... But it didn't work, so I thought that my problem was not related to Now i tried: // rector.php
// ...
// HERE IS THE FIX!
$parameters->set(Option::AUTOLOAD_PATHS, [
__DIR__.'/vendor/acme/my-custom-package/src',
]);
// ... And everything works fine... is this a correct configuration? Thank you |
that's possibly due to symlink usage, if that's the only way, that possibly worth to be mentioned to documentation, could you create PR for it? |
Hi, thank you for your feedback! Unfortunately I don't think that symlinks can be the culprit here since my main project is not using them at all (they are used in the reproducer to simplify the setup). I couldn't find a better way to solve it, so it may be worth to mention it (at least until we figure out a better solution). |
Yes please, you may need to make it under |
Please create PR to rector-src https://github.com/rectorphp/rector-src/blob/main/build/target-repository/docs/static_reflection_and_autoload.md |
Bug Report
Issue description
Rector fails with a
Class ... was not found while trying to analyse it...
when a dependency is using attributes andJsonSerializable
in an abstract class.Additional info: it's not a matter of which rules are enabled, the command fails even with no rule enabled.
Minimal PHP Code Causing Issue
This issue appears while using composer dependencies so I had to create a
reproducer(I tried to keep it minimal).Run:
Removing the
#[Test]
attribute orimplements JsonSerializable
fromAbstractClass.phpremoves the error.Update 2021-09-15
I'm removing the repository since #6688 (comment), here is a brief description of the example.
I had two projects:
The dependency had an abstract class implementing
JsonSerializable
:The project was using a direct child of
AbstractClass
(the actual implementation doesn't matter). Rector fails with the error above, but removing the PHP attribute or the interface implementation fromAbstractClass
removes the error.Expected Behaviour
The
MyCode\AbstractClass
class should be loaded successfully as is.Thank you for your time.
The text was updated successfully, but these errors were encountered: