From c0340053d1b95718f18cb04a43190483b8c7268d Mon Sep 17 00:00:00 2001 From: Elliot Levin Date: Mon, 11 Aug 2014 21:41:54 +0200 Subject: [PATCH] Fix case sensitivity for special class names --- lib/PhpParser/NodeVisitor/NameResolver.php | 2 +- .../NodeVisitor/NameResolverTest.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index cdac1f7..2850fef 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -122,7 +122,7 @@ class NameResolver extends NodeVisitorAbstract protected function resolveClassName(Name $name) { // don't resolve special class names - if (in_array((string) $name, array('self', 'parent', 'static'))) { + if (in_array(strtolower($name), array('self', 'parent', 'static'))) { return $name; } diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php index c13ccde..ec88238 100644 --- a/test/PhpParser/NodeVisitor/NameResolverTest.php +++ b/test/PhpParser/NodeVisitor/NameResolverTest.php @@ -314,4 +314,35 @@ EOC; $this->assertEquals(array('Bar', 'Baz'), $stmt->stmts[1]->expr->class->parts); } + + public function testSpecialClassNamesAreCaseInsensitive() { + $source = <<<'EOC' +parse($source); + + $traverser = new PhpParser\NodeTraverser; + $traverser->addVisitor(new NameResolver); + + $stmts = $traverser->traverse($stmts); + $classStmt = $stmts[0]; + $methodStmt = $classStmt->stmts[0]->stmts[0]; + + $this->assertEquals('SELF', (string)$methodStmt->stmts[0]->class); + $this->assertEquals('PARENT', (string)$methodStmt->stmts[1]->class); + $this->assertEquals('static', (string)$methodStmt->stmts[2]->class); + } }