1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-20 04:36:57 +01:00

Merge branch '0.9'

Conflicts:
	lib/PhpParser/Lexer.php
	lib/PhpParser/Node/Stmt/Class.php
	lib/PhpParser/Node/Stmt/ClassMethod.php
	lib/PhpParser/Node/Stmt/Interface.php
	lib/PhpParser/Node/Stmt/Namespace.php
	lib/PhpParser/Node/Stmt/UseUse.php
	lib/PhpParser/Parser.php
This commit is contained in:
nikic 2014-02-12 20:23:12 +01:00
commit 1c8481bff6
14 changed files with 61 additions and 44 deletions

View File

@ -166,7 +166,7 @@ inner_statement:
statement { $$ = $1; }
| function_declaration_statement { $$ = $1; }
| class_declaration_statement { $$ = $1; }
| T_HALT_COMPILER { error('__halt_compiler() can only be used from the outermost scope'); }
| T_HALT_COMPILER { error('__HALT_COMPILER() can only be used from the outermost scope'); }
;
statement:

View File

@ -148,7 +148,7 @@ class Lexer
// this simplifies the situation, by not allowing any comments
// in between of the tokens.
if (!preg_match('~\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) {
throw new Error('__halt_compiler must be followed by "();"');
throw new Error('__HALT_COMPILER must be followed by "();"');
}
// prevent the lexer from returning any further tokens
@ -192,4 +192,4 @@ class Lexer
return $tokenMap;
}
}
}

View File

@ -51,16 +51,16 @@ class Class_ extends Node\Stmt
$this->name = $name;
if (isset(self::$specialNames[(string) $this->name])) {
throw new Error(sprintf('Cannot use "%s" as class name as it is reserved', $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])) {
throw new Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->extends));
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends));
}
foreach ($this->implements as $interface) {
if (isset(self::$specialNames[(string) $interface])) {
throw new Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface));
throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface));
}
}
}
@ -101,7 +101,7 @@ class Class_ extends Node\Stmt
}
if ($a & 48 && $b & 48) {
throw new Error('Cannot use the final and abstract modifier at the same time');
throw new Error('Cannot use the final modifier on an abstract class member');
}
}
}
}

View File

@ -38,10 +38,15 @@ class ClassMethod extends Node\Stmt
);
$this->name = $name;
if (($this->type & Class_::MODIFIER_STATIC)
&& ('__construct' == $this->name || '__destruct' == $this->name || '__clone' == $this->name)
) {
throw new Error(sprintf('"%s" method cannot be static', $this->name));
if ($this->type & Class_::MODIFIER_STATIC) {
switch (strtolower($this->name)) {
case '__construct':
throw new Error(sprintf('Constructor %s() cannot be static', $this->name));
case '__destruct':
throw new Error(sprintf('Destructor %s() cannot be static', $this->name));
case '__clone':
throw new Error(sprintf('Clone method %s() cannot be static', $this->name));
}
}
}
@ -68,4 +73,4 @@ class ClassMethod extends Node\Stmt
public function isStatic() {
return (bool) ($this->type & Class_::MODIFIER_STATIC);
}
}
}

View File

@ -38,13 +38,13 @@ class Interface_ extends Node\Stmt
$this->name = $name;
if (isset(self::$specialNames[(string) $this->name])) {
throw new Error(sprintf('Cannot use "%s" as interface name as it is reserved', $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])) {
throw new Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface));
throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface));
}
}
}
}
}

View File

@ -34,7 +34,7 @@ class Namespace_ extends Node\Stmt
);
if (isset(self::$specialNames[(string) $this->name])) {
throw new Error(sprintf('Cannot use "%s" as namespace name as it is reserved', $this->name));
throw new Error(sprintf('Cannot use \'%s\' as namespace name', $this->name));
}
if (null !== $this->stmts) {
@ -124,4 +124,4 @@ class Namespace_ extends Node\Stmt
return $newStmts;
}
}
}
}

View File

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

View File

@ -1228,7 +1228,7 @@ class Parser
}
protected function yyn29($attributes) {
throw new Error('__halt_compiler() can only be used from the outermost scope');
throw new Error('__HALT_COMPILER() can only be used from the outermost scope');
}
protected function yyn30($attributes) {

View File

@ -22,8 +22,8 @@ Multiple final modifiers are not allowed on line 1
-----
<?php class A { abstract final a(); }
-----
Cannot use the final and abstract modifier at the same time on line 1
Cannot use the final modifier on an abstract class member on line 1
-----
<?php abstract final class A { }
-----
Syntax error, unexpected T_FINAL, expecting T_CLASS on line 1
Syntax error, unexpected T_FINAL, expecting T_CLASS on line 1

View File

@ -2,11 +2,11 @@ Invalid class name
-----
<?php class self {}
-----
Cannot use "self" as class name as it is reserved on line 1
Cannot use 'self' as class name as it is reserved on line 1
-----
<?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 {}
-----
@ -14,11 +14,11 @@ Syntax error, unexpected T_STATIC, expecting T_STRING on line 1
-----
<?php class A extends self {}
-----
Cannot use "self" as class name as it is reserved on line 1
Cannot use 'self' as class name as it is reserved on line 1
-----
<?php class A extends 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 A extends static {}
-----
@ -26,11 +26,11 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEP
-----
<?php class A implements self {}
-----
Cannot use "self" as interface name as it is reserved on line 1
Cannot use 'self' as interface name as it is reserved on line 1
-----
<?php class A implements parent {}
-----
Cannot use "parent" as interface name as it is reserved on line 1
Cannot use 'parent' as interface name as it is reserved on line 1
-----
<?php class A implements static {}
-----
@ -38,11 +38,11 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEP
-----
<?php interface self {}
-----
Cannot use "self" as interface name as it is reserved on line 1
Cannot use 'self' as class name as it is reserved on line 1
-----
<?php interface parent {}
-----
Cannot use "parent" as interface name as it is reserved on line 1
Cannot use 'parent' as class name as it is reserved on line 1
-----
<?php interface static {}
-----
@ -50,12 +50,12 @@ Syntax error, unexpected T_STATIC, expecting T_STRING on line 1
-----
<?php interface A extends self {}
-----
Cannot use "self" as interface name as it is reserved on line 1
Cannot use 'self' as interface name as it is reserved on line 1
-----
<?php interface A extends parent {}
-----
Cannot use "parent" as interface name as it is reserved on line 1
Cannot use 'parent' as interface name as it is reserved on line 1
-----
<?php interface A extends static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR on line 1
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR on line 1

View File

@ -2,12 +2,24 @@ Some special methods cannot be static
-----
<?php class A { static function __construct() {} }
-----
"__construct" method cannot be static on line 1
Constructor __construct() cannot be static on line 1
-----
<?php class A { static function __destruct() {} }
-----
"__destruct" method cannot be static on line 1
Destructor __destruct() cannot be static on line 1
-----
<?php class A { static function __clone() {} }
-----
"__clone" method cannot be static on line 1
Clone method __clone() cannot be static on line 1
-----
<?php class A { static function __CONSTRUCT() {} }
-----
Constructor __CONSTRUCT() cannot be static on line 1
-----
<?php class A { static function __Destruct() {} }
-----
Destructor __Destruct() cannot be static on line 1
-----
<?php class A { static function __cLoNe() {} }
-----
Clone method __cLoNe() cannot be static on line 1

View File

@ -3,4 +3,4 @@ Invalid __halt_compiler() syntax
<?php
__halt_compiler()
-----
__halt_compiler must be followed by "();" on line 2
__HALT_COMPILER must be followed by "();" on line 2

View File

@ -5,4 +5,4 @@ if (true) {
__halt_compiler();
}
-----
__halt_compiler() can only be used from the outermost scope on line 3
__HALT_COMPILER() can only be used from the outermost scope on line 3

View File

@ -2,11 +2,11 @@ Invalid namespace names
-----
<?php namespace self;
-----
Cannot use "self" as namespace name as it is reserved on line 1
Cannot use 'self' as namespace name on line 1
-----
<?php namespace parent;
-----
Cannot use "parent" as namespace name as it is reserved on line 1
Cannot use 'parent' as namespace name on line 1
-----
<?php namespace static;
-----
@ -14,12 +14,12 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{' o
-----
<?php use A as self;
-----
Cannot use "A" as "self" because "self" is a special class name on line 1
Cannot use A as self because 'self' is a special class name on line 1
-----
<?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;
-----
Syntax error, unexpected T_STATIC, expecting T_STRING on line 1
Syntax error, unexpected T_STATIC, expecting T_STRING on line 1