From 2b54c877898bead256983d388b52096859d68d6e Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Fri, 3 Jan 2020 07:00:15 -0500 Subject: [PATCH 1/2] 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..1b636700e7e 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($tokens[$key-2][0] === T_NEW) { + break; + } // Increment stat for found class. $this->incrementProgressStat( self::OUTPUT_PROGRESS_PHASE2, 'classCount' ); From 697e74198e57ae0123e4438a60516807bd8f83fa Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Fri, 3 Jan 2020 07:03:12 -0500 Subject: [PATCH 2/2] Make autoloads ignore anonymous classes --- kernel/private/classes/ezautoloadgenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/private/classes/ezautoloadgenerator.php b/kernel/private/classes/ezautoloadgenerator.php index 1b636700e7e..96f4a1b38d4 100644 --- a/kernel/private/classes/ezautoloadgenerator.php +++ b/kernel/private/classes/ezautoloadgenerator.php @@ -643,7 +643,7 @@ protected function getClassFileList( $fileList, $mode ) * @see https://www.php.net/manual/en/language.oop5.anonymous.php * NEW_TOKEN - WHITESPACE_TOKEN - CLASS_TOKEN */ - if($tokens[$key-2][0] === T_NEW) { + if(isset($tokens[$key-2][0]) && $tokens[$key-2][0] === T_NEW) { break; }