Make special class name checks case insensitive

This commit is contained in:
Nikita Popov 2015-04-26 23:13:08 +02:00
parent e1a0ec3724
commit 55b2ead967
6 changed files with 21 additions and 21 deletions

View File

@ -48,11 +48,11 @@ class Class_ extends ClassLike
$this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
if (null !== $this->name && isset(self::$specialNames[$this->name])) {
if (null !== $this->name && isset(self::$specialNames[strtolower($this->name)])) {
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
}
if (isset(self::$specialNames[(string) $this->extends])) {
if (isset(self::$specialNames[strtolower($this->extends)])) {
throw new Error(
sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends),
$this->extends->getAttributes()
@ -60,7 +60,7 @@ class Class_ extends ClassLike
}
foreach ($this->implements as $interface) {
if (isset(self::$specialNames[(string) $interface])) {
if (isset(self::$specialNames[strtolower($interface)])) {
throw new Error(
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
$interface->getAttributes()

View File

@ -31,12 +31,12 @@ class Interface_ extends ClassLike
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
if (isset(self::$specialNames[(string) $this->name])) {
if (isset(self::$specialNames[strtolower($this->name)])) {
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
}
foreach ($this->extends as $interface) {
if (isset(self::$specialNames[(string) $interface])) {
if (isset(self::$specialNames[strtolower($interface)])) {
throw new Error(
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
$interface->getAttributes()

View File

@ -30,7 +30,7 @@ class Namespace_ extends Node\Stmt
$this->name = $name;
$this->stmts = $stmts;
if (isset(self::$specialNames[(string) $this->name])) {
if (isset(self::$specialNames[strtolower($this->name)])) {
throw new Error(
sprintf('Cannot use \'%s\' as namespace name', $this->name),
$this->name->getAttributes()

View File

@ -24,7 +24,7 @@ class UseUse extends Node\Stmt
$alias = $name->getLast();
}
if ('self' == $alias || 'parent' == $alias) {
if ('self' == strtolower($alias) || 'parent' == strtolower($alias)) {
throw new Error(sprintf(
'Cannot use %s as %s because \'%2$s\' is a special class name',
$name, $alias

View File

@ -4,9 +4,9 @@ Invalid class name
-----
Cannot use 'self' as class name as it is reserved on line 1
-----
<?php class parent {}
<?php class PARENT {}
-----
Cannot use 'parent' as class name as it is reserved on line 1
Cannot use 'PARENT' as class name as it is reserved on line 1
-----
<?php class static {}
-----
@ -16,9 +16,9 @@ Syntax error, unexpected T_STATIC, expecting T_STRING from 1:13 to 1:18
-----
Cannot use 'self' as class name as it is reserved from 1:23 to 1:26
-----
<?php class A extends parent {}
<?php class A extends PARENT {}
-----
Cannot use 'parent' as class name as it is reserved from 1:23 to 1:28
Cannot use 'PARENT' as class name as it is reserved from 1:23 to 1:28
-----
<?php class A extends static {}
-----
@ -28,9 +28,9 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEP
-----
Cannot use 'self' as interface name as it is reserved from 1:26 to 1:29
-----
<?php class A implements parent {}
<?php class A implements PARENT {}
-----
Cannot use 'parent' as interface name as it is reserved from 1:26 to 1:31
Cannot use 'PARENT' as interface name as it is reserved from 1:26 to 1:31
-----
<?php class A implements static {}
-----
@ -40,9 +40,9 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEP
-----
Cannot use 'self' as class name as it is reserved on line 1
-----
<?php interface parent {}
<?php interface PARENT {}
-----
Cannot use 'parent' as class name as it is reserved on line 1
Cannot use 'PARENT' as class name as it is reserved on line 1
-----
<?php interface static {}
-----
@ -52,9 +52,9 @@ Syntax error, unexpected T_STATIC, expecting T_STRING from 1:17 to 1:22
-----
Cannot use 'self' as interface name as it is reserved from 1:27 to 1:30
-----
<?php interface A extends parent {}
<?php interface A extends PARENT {}
-----
Cannot use 'parent' as interface name as it is reserved from 1:27 to 1:32
Cannot use 'PARENT' as interface name as it is reserved from 1:27 to 1:32
-----
<?php interface A extends static {}
-----

View File

@ -4,9 +4,9 @@ Invalid namespace names
-----
Cannot use 'self' as namespace name from 1:17 to 1:20
-----
<?php namespace parent;
<?php namespace PARENT;
-----
Cannot use 'parent' as namespace name from 1:17 to 1:22
Cannot use 'PARENT' as namespace name from 1:17 to 1:22
-----
<?php namespace static;
-----
@ -16,9 +16,9 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{' f
-----
Cannot use A as self because 'self' is a special class name on line 1
-----
<?php use B as parent;
<?php use B as PARENT;
-----
Cannot use B as parent because 'parent' is a special class name on line 1
Cannot use B as PARENT because 'PARENT' is a special class name on line 1
-----
<?php use C as static;
-----