From 979b477a0261f58d189c99720aba3d51e2768bc6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 3 May 2023 15:05:35 +0200 Subject: [PATCH] Remove `file_exists()` check from production autoloader Resolves #5002 --- .../install/files/lib/system/WCF.class.php | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 58d9d4f567..8ec1490d73 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -821,31 +821,41 @@ class WCF // PHP will implicitly check if the file exists when including it, which means that we can save a // redundant syscall/fs access by not checking for existence ourselves. Do not use require_once()! - - // TODO: Changed for #4684. Revert for release. - if (\file_exists($classPath)) { - include_once($classPath); - } + @include_once($classPath); } } } /** - * Checks the class name casing after autoloading. + * Checks the class name casing after autoloading and does not suppress + * errors during loading. */ final public static function autoloadDebug(string $className): void { - self::autoload($className); + $originalClassName = $className; - if (\class_exists($className)) { - $reflection = new \ReflectionClass($className); + // This is copy and pasted from self::autoload(). The $classPath calculation + // logic cannot be moved into a shared function, because it + // measurably reduced autoloader performance. + $className = \strtr($className, '\\', '/'); + if (($slashPos = \strpos($className, '/')) !== null) { + $applicationPrefix = \substr($className, 0, $slashPos); + if (isset(self::$autoloadDirectories[$applicationPrefix])) { + $classPath = self::$autoloadDirectories[$applicationPrefix] . \substr($className, $slashPos + 1) . '.class.php'; + + if (\file_exists($classPath)) { + require_once($classPath); - if ($className !== $reflection->getName()) { - throw new \Exception(\sprintf( - "Loaded class '%s' with mismatching case '%s'. This will cause issues on case-sensitive file systems.", - $reflection->getName(), - $className, - )); + $reflection = new \ReflectionClass($originalClassName); + + if ($originalClassName !== $reflection->getName()) { + throw new \Exception(\sprintf( + "Loaded class '%s' with mismatching case '%s'. This will cause issues on case-sensitive file systems.", + $reflection->getName(), + $originalClassName, + )); + } + } } } } -- 2.20.1