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:
parent
39f323b5ad
commit
c0340053d1
@ -122,7 +122,7 @@ class NameResolver extends NodeVisitorAbstract
|
|||||||
|
|
||||||
protected function resolveClassName(Name $name) {
|
protected function resolveClassName(Name $name) {
|
||||||
// don't resolve special class names
|
// 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;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,4 +314,35 @@ EOC;
|
|||||||
|
|
||||||
$this->assertEquals(array('Bar', 'Baz'), $stmt->stmts[1]->expr->class->parts);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user