Skip to content

Commit

Permalink
Merge branch '0.9'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikic committed Feb 12, 2014
2 parents 523e024 + 118f283 commit 1c8481b
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 44 deletions.
2 changes: 1 addition & 1 deletion grammar/zend_language_parser.phpy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function handleHaltCompiler() {
// 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
Expand Down Expand Up @@ -192,4 +192,4 @@ protected function createTokenMap() {

return $tokenMap;
}
}
}
10 changes: 5 additions & 5 deletions lib/PhpParser/Node/Stmt/Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public function __construct($name, array $subNodes = array(), array $attributes
$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));
}
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ public static function verifyModifier($a, $b) {
}

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');
}
}
}
}
15 changes: 10 additions & 5 deletions lib/PhpParser/Node/Stmt/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public function __construct($name, array $subNodes = array(), array $attributes
);
$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));
}
}
}

Expand All @@ -68,4 +73,4 @@ public function isFinal() {
public function isStatic() {
return (bool) ($this->type & Class_::MODIFIER_STATIC);
}
}
}
6 changes: 3 additions & 3 deletions lib/PhpParser/Node/Stmt/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public function __construct($name, array $subNodes = array(), array $attributes
$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));
}
}
}
}
}
4 changes: 2 additions & 2 deletions lib/PhpParser/Node/Stmt/Namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(Node\Name $name = null, $stmts = array(), array $att
);

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) {
Expand Down Expand Up @@ -124,4 +124,4 @@ public static function postprocess(array $stmts) {
return $newStmts;
}
}
}
}
4 changes: 2 additions & 2 deletions lib/PhpParser/Node/Stmt/UseUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(Node\Name $name, $alias = null, array $attributes =

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
));
}
Expand All @@ -38,4 +38,4 @@ public function __construct(Node\Name $name, $alias = null, array $attributes =
$attributes
);
}
}
}
2 changes: 1 addition & 1 deletion lib/PhpParser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ protected function yyn28($attributes) {
}

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) {
Expand Down
4 changes: 2 additions & 2 deletions test/code/parser/stmt/class/modifier.test-fail
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions test/code/parser/stmt/class/name.test-fail
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@ 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 {}
-----
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 {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR on line 1
-----
<?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 {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR on line 1
-----
<?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 {}
-----
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
18 changes: 15 additions & 3 deletions test/code/parser/stmt/class/staticMethod.test-fail
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/code/parser/stmt/haltCompilerInvalidSyntax.test-fail
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/code/parser/stmt/haltCompilerOutermostScope.test-fail
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions test/code/parser/stmt/namespace/name.test-fail
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ 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;
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{' on line 1
-----
<?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

0 comments on commit 1c8481b

Please sign in to comment.