1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Fix case sensitivity for special class names

This commit is contained in:
Elliot Levin 2014-08-11 21:41:54 +02:00 committed by nikic
parent 39f323b5ad
commit c0340053d1
2 changed files with 32 additions and 1 deletions

View File

@ -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;
}

View File

@ -314,4 +314,35 @@ EOC;
$this->assertEquals(array('Bar', 'Baz'), $stmt->stmts[1]->expr->class->parts);
}
public function testSpecialClassNamesAreCaseInsensitive() {
$source = <<<'EOC'
<?php
namespace Foo;
class Bar
{
public static function method()
{
SELF::method();
PARENT::method();
STATIC::method();
}
}
EOC;
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
$stmts = $parser->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);
}
}