Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DebugClassLoader] Can't recover on a failed required file #32499

Closed
@fancyweb

Description

@fancyweb

Symfony version(s) affected: all

Description
In the DebugClassLoader, classes that are found by the wrapped class loader findFile() method are required (and not included like in the composer ClassLoader for example). That means that if the file is not found, the fatal error that is triggered is not recoverable.

So why would the wrapped class loader finds the file but the file doesn't actually exist? With Composer, it can happen if you dump your autoload files with the optimize option and if you delete a class file for example. The class will still be in the Composer class map.

What problem does it cause? When you do reflection on a class like this, it ends up with a fatal error instead of a \ReflectionException. In Symfony, that breaks the AnnotationCacheWarmer process that is supposed to ignore \ReflectionExceptions on classes that don't exist.

Possible Solution

  • Check if the file exists before requiring it in the DebugClassLoader : I guess it would be very bad for performance.
  • Create a SafeDebugClassLoader that wraps the DebugClassLoader to check if the file exists, so we can enable it / disable it on demand?

@nicolas-grekas 🙏

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions