Skip to content

ReflectionClassResource not excluding vendor methods #61622

@kicken

Description

@kicken

Symfony version(s) affected

7.3

Description

When testing if the container needs to be rebuilt, the ReflectionClassResource class does not exclude the methods defined by classes in the vendor folder, resulting in a different signature and thus constant unnecessary container rebuilds.

When symfony adds a class resource to the container, it constructs the ReflectionClassResource with the excludedVendors property defined and thus methods defined in a parent class in the vendor folder (ie, AbstractController) are excluded when generating the signature to hash.

When the resource is unserialized from the meta data to check if the cache is fresh, the excludedVendors property is no longer defined, so the methods of parent classes in the vendor folder are included in the signature resulting in a different hash and symfony thinking the cache is stale.

The result is the container gets rebuilt after any change to a file, rather than only when a signature is changed. This wastes a lot of time in development where container rebuilds can be very slow with xdebug enabled.

How to reproduce

  • Create a Symfony web application
  • Add a simple controller like so:
 #[Route('/')] public function __invoke() : Response{ $min = 1000; $max = 9999; return new Response('Your number: ' . mt_rand($min, $max)); } } 
  • Load the page to build the container cache.
  • Change the value of $max to 8888
  • Reload the page, container gets re-built unnecessarily.

Possible Solution

Adding the excludedVendors property to the array returned by ReflectionClassResource::__sleep fixes the issue.

Additional Context

Excluding vendor methods from the signature appears to have been added in commit 60f0fca

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