Skip to content

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

Open
@DeveloperRob

Description

@DeveloperRob

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)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions