diff --git a/grammar/zend_language_parser.phpy b/grammar/zend_language_parser.phpy index 12c455b..4cfd4d9 100644 --- a/grammar/zend_language_parser.phpy +++ b/grammar/zend_language_parser.phpy @@ -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: diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index 68b3298..eb350c7 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -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; } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Node/Stmt/Class.php b/lib/PhpParser/Node/Stmt/Class.php index 4f873cf..998a5cb 100644 --- a/lib/PhpParser/Node/Stmt/Class.php +++ b/lib/PhpParser/Node/Stmt/Class.php @@ -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'); } } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 07bb26a..d650180 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -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); } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Node/Stmt/Interface.php b/lib/PhpParser/Node/Stmt/Interface.php index 23228b8..f3d6d1f 100644 --- a/lib/PhpParser/Node/Stmt/Interface.php +++ b/lib/PhpParser/Node/Stmt/Interface.php @@ -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)); } } } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Node/Stmt/Namespace.php b/lib/PhpParser/Node/Stmt/Namespace.php index 8f3dcdc..a329e4d 100644 --- a/lib/PhpParser/Node/Stmt/Namespace.php +++ b/lib/PhpParser/Node/Stmt/Namespace.php @@ -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; } } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Node/Stmt/UseUse.php b/lib/PhpParser/Node/Stmt/UseUse.php index 01be0fb..7ec8548 100644 --- a/lib/PhpParser/Node/Stmt/UseUse.php +++ b/lib/PhpParser/Node/Stmt/UseUse.php @@ -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 ); } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Parser.php b/lib/PhpParser/Parser.php index ef19e3a..df6b4df 100644 --- a/lib/PhpParser/Parser.php +++ b/lib/PhpParser/Parser.php @@ -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) { diff --git a/test/code/parser/stmt/class/modifier.test-fail b/test/code/parser/stmt/class/modifier.test-fail index b1bfc72..7272b4c 100644 --- a/test/code/parser/stmt/class/modifier.test-fail +++ b/test/code/parser/stmt/class/modifier.test-fail @@ -22,8 +22,8 @@ Multiple final modifiers are not allowed on line 1 -----