-
-
Notifications
You must be signed in to change notification settings - Fork 67
Handle anonymous classes more gracefully #286
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
Conversation
It does not necessary hold a proxy class.
I think you also need to update |
@@ -462,7 +468,7 @@ public function isTransient($className) | |||
} | |||
|
|||
// Check for namespace alias | |||
if (strpos($className, ':') !== false) { | |||
if (! class_exists($className) && strpos($className, ':') !== false) { |
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 would use ! class_exists($className, false)
, to avoid triggering autoloaders for namespace aliases. Excluding anonymous classes does not need to trigger the autoloader.
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.
btw, other class_exists
checks added in the PR in the anonymous class checks should probably do the same, as they are added before the resolution of the real class name which resolves aliases.
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 that makes sense, since we want to test if the class is anonymous and anonymous classes surely don't require any autoloading.
@@ -220,6 +222,10 @@ abstract protected function isEntity(ClassMetadata $class); | |||
*/ | |||
public function getMetadataFor($className) | |||
{ | |||
if (class_exists($className, false) && (new ReflectionClass($className))->isAnonymous()) { |
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 we put that after the check of the cache, to avoid paying the cost of this reflection check when retrieving metadata that was already loaded (which is something that the ORM does a lot, including in its critical path) ?
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.
Sure 👍
In some situations, they were mistaken for short aliases.
* doctrine/persistence to doctrine/persistence#286 * symfony/property-info to get symfony/symfony#40457
* doctrine/persistence to doctrine/persistence#286 * symfony/property-info to get symfony/symfony#40457
* doctrine/persistence to doctrine/persistence#286 * symfony/property-info to get symfony/symfony#40457
* doctrine/persistence to doctrine/persistence#286 * symfony/property-info to get symfony/symfony#40457
Fixes #24