From 11362cc1bdf46b80eefbecd0294dd962ffded138 Mon Sep 17 00:00:00 2001 From: pkamps Date: Fri, 3 Jan 2020 13:04:27 +0100 Subject: [PATCH] Make autoloads ignore anonymous classes (#174) * Make autoloads ignore anonymous classes * Make autoloads ignore anonymous classes --- kernel/private/classes/ezautoloadgenerator.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/private/classes/ezautoloadgenerator.php b/kernel/private/classes/ezautoloadgenerator.php index 0efd3692283..96f4a1b38d4 100644 --- a/kernel/private/classes/ezautoloadgenerator.php +++ b/kernel/private/classes/ezautoloadgenerator.php @@ -638,6 +638,14 @@ protected function getClassFileList( $fileList, $mode ) if ($tokens[$key-1][1] === '::') { break; } + /** + * Ignore token if class is anonymous: "new Class() {}" + * @see https://www.php.net/manual/en/language.oop5.anonymous.php + * NEW_TOKEN - WHITESPACE_TOKEN - CLASS_TOKEN + */ + if(isset($tokens[$key-2][0]) && $tokens[$key-2][0] === T_NEW) { + break; + } // Increment stat for found class. $this->incrementProgressStat( self::OUTPUT_PROGRESS_PHASE2, 'classCount' );