Synchronized error messages with native php error messages

This commit is contained in:
Martin Hasoň 2014-01-23 13:33:02 +01:00 committed by nikic
parent 6f36a88993
commit 118f28344d
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 PHPParser_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 PHPParser_Error('__halt_compiler must be followed by "();"');
throw new PHPParser_Error('__HALT_COMPILER must be followed by "();"');
}
// prevent the lexer from returning any further tokens

View File

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

View File

@ -33,10 +33,15 @@ class PHPParser_Node_Stmt_ClassMethod extends PHPParser_Node_Stmt
);
$this->name = $name;
if (($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC)
&& ('__construct' == $this->name || '__destruct' == $this->name || '__clone' == $this->name)
) {
throw new PHPParser_Error(sprintf('"%s" method cannot be static', $this->name));
if ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC) {
switch (strtolower($this->name)) {
case '__construct':
throw new PHPParser_Error(sprintf('Constructor %s() cannot be static', $this->name));
case '__destruct':
throw new PHPParser_Error(sprintf('Destructor %s() cannot be static', $this->name));
case '__clone':
throw new PHPParser_Error(sprintf('Clone method %s() cannot be static', $this->name));
}
}
}

View File

@ -33,12 +33,12 @@ class PHPParser_Node_Stmt_Interface extends PHPParser_Node_Stmt
$this->name = $name;
if (isset(self::$specialNames[(string) $this->name])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $this->name));
throw new PHPParser_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 PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface));
throw new PHPParser_Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface));
}
}
}

View File

@ -29,7 +29,7 @@ class PHPParser_Node_Stmt_Namespace extends PHPParser_Node_Stmt
);
if (isset(self::$specialNames[(string) $this->name])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as namespace name as it is reserved', $this->name));
throw new PHPParser_Error(sprintf('Cannot use \'%s\' as namespace name', $this->name));
}
if (null !== $this->stmts) {

View File

@ -20,7 +20,7 @@ class PHPParser_Node_Stmt_UseUse extends PHPParser_Node_Stmt
if ('self' == $alias || 'parent' == $alias) {
throw new PHPParser_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
));
}

View File

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

View File

@ -22,7 +22,7 @@ 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 { }
-----

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,11 +50,11 @@ 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 {}
-----

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,11 +14,11 @@ 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;
-----