From c3f795e909ba931b9476788040c8ea760b0b25c2 Mon Sep 17 00:00:00 2001 From: isaackaara Date: Wed, 4 Mar 2026 19:15:04 +0300 Subject: [PATCH] fix: skip autoload exception when class existence is being checked (#1764) The MetaCommand's custom autoloader throws a ReflectionException for any class not found during meta generation. However, this breaks libraries that use class_exists() to check for optional dependencies before loading them (e.g. Doctrine ORM checking for StaticReflectionService removed in doctrine/persistence v4). This fix checks the call stack (up to 3 frames) for class_exists(), interface_exists(), trait_exists(), or enum_exists() calls and returns gracefully instead of throwing, allowing the existence check to return false as expected. Fixes #1750 --- src/Console/MetaCommand.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php index fe5189e..61cb96f 100644 --- a/src/Console/MetaCommand.php +++ b/src/Console/MetaCommand.php @@ -195,6 +195,18 @@ class MetaCommand extends Command return; } + // Don't throw when class existence is being checked via class_exists(), + // interface_exists(), trait_exists(), or enum_exists(). These functions + // expect the autoloader to return gracefully when the class doesn't exist. + // Throwing here would break libraries that use class_exists() to check for + // optional dependencies (e.g. Doctrine ORM checking for removed classes). + $existsFunctions = ['class_exists', 'interface_exists', 'trait_exists', 'enum_exists']; + foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3) as $frame) { + if (isset($frame['function']) && in_array($frame['function'], $existsFunctions, true)) { + return; + } + } + throw new \ReflectionException("Class '$class' not found."); };