Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single word namespaces which are reserved words produce an error incorrectly #362

Open
DeveloperRob opened this issue Nov 24, 2021 · 1 comment

Comments

@DeveloperRob
Copy link

PR 331 doesn't support PHP8 valid namespaces which are a single non-string token. For instance, while the first code block will work without issue on PHP8 (as T_NAME_QUALIFIED will be split to T_STRING T_NS_SEPARATOR T_STRING, resulting in Abstract being a T_STRING), the second will fail as token_get_all returns T_ABSTRACT and so the parser thinks that the namespace declaration is incomplete.

Works:

namespace Abstract\Objects;

class Foo{}

Valid PHP but doesn't work:

namespace Abstract;

class Foo{}

(DiagnosticsProvider::getDiagnostics($astNode); returns):

array(2) {
  [0] =>
  class Microsoft\PhpParser\Diagnostic#22 (4) {
    public $kind =>
    int(0)
    public $message =>
    string(13) "';' expected."
    public $start =>
    int(16)
    public $length =>
    int(0)
  }
  [1] =>
  class Microsoft\PhpParser\Diagnostic#23 (4) {
    public $kind =>
    int(0)
    public $message =>
    string(21) "Unexpected 'abstract'"
    public $start =>
    int(17)
    public $length =>
    int(8)
  }
}
@TysonAndre
Copy link
Contributor

/* Name usable in a namespace declaration. */
namespace_declaration_name:
		identifier								{ $$ = $1; }
	|	T_NAME_QUALIFIED						{ $$ = $1; }
;

namespace declaration names in php 8.0+ seem distinct from any other token - they can be one or more of any reserved word, keyword, or regular string separated by \. Keywords were forbidden before that.

(T_NAME_QUALIFIED is the case of 2 or more without whitespace, identifier is the single case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants