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
Detection of circular references #1240
Conversation
src/Reflection/ReflectionClass.php
Outdated
if ($this->cachedParentClassNames === null) { | ||
$parentClassNames = []; | ||
|
||
$parentClass = $this->getParentClass(); | ||
while ($parentClass !== null) { | ||
$parentClassName = $parentClass->getName(); | ||
|
||
if ( | ||
$this->name === $parentClassName | ||
|| in_array($parentClassName, $parentClassNames, true) | ||
) { | ||
throw CircularReference::fromClassName($parentClassName); | ||
} | ||
|
||
$parentClassNames[] = $parentClassName; | ||
$parentClass = $parentClass->getParentClass(); | ||
} | ||
|
||
$this->cachedParentClassNames = $parentClassNames; | ||
} |
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.
Can we implement this check without having a mutable $this->cachedParentClassNames
? Thinking of a by-ref parameter in a private
method 🤔
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.
Is is such a problem? ReflectionClass
already have some more caches...
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.
No, it's not, just trying to push the design for less stateful changes: can roll with the current solution too.
In practice, at some point, my aim is to have everything readonly
:)
thank you for working on this! You beat me to opening a PR :) Looks like this will make it into 6.0, nice |
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.
LGTM, nice! 👍
Nice. Maybe this is similar to the endless loop we see in phpstan/phpstan#8054 ? |
Fixes #1165