diff --git a/src/Parser.php b/src/Parser.php index 0a3f480..3c2ccf4 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -589,6 +589,11 @@ private function classTokenNeedsProcessing($position) { return false; } + // PHP 8 allows keywords as named arguments: new Foo(class: $bar) + if ($this->tokenArray[$position + 1] === ':' || $this->tokenArray[$position + 2] === ':') { + return false; + } + return true; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 6595483..21db020 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -138,6 +138,15 @@ public function testMultipleClasses() { $this->assertContains('demo3', $classes); } + /** + * @requires PHP 8.0 + */ + public function testNamedArgumentReusingClassKeywordGetsIgnored() { + $parser = new Parser(); + $rc = $parser->parse(new SourceFile((__DIR__.'/_data/parser/named-argument-class.php'))); + $this->assertEquals(array('foo'), $rc->getUnits()); + } + public function testExtends() { $parser = new \TheSeer\Autoload\Parser; $rc = $parser->parse(new SourceFile((__DIR__.'/_data/parser/extends.php'))); diff --git a/tests/_data/parser/named-argument-class.php b/tests/_data/parser/named-argument-class.php new file mode 100644 index 0000000..5a947af --- /dev/null +++ b/tests/_data/parser/named-argument-class.php @@ -0,0 +1,15 @@ +