Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TokenParser.php

function TokenParser::__construct

File

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php, line 49

Class

TokenParser
Parses a file for namespaces/use/class declarations.

Namespace

Doctrine\Common\Annotations

Code

public function __construct(string $contents) {
    $this->tokens = token_get_all($contents);
    // The PHP parser sets internal compiler globals for certain things. Annoyingly, the last docblock comment it
    // saw gets stored in doc_comment. When it comes to compile the next thing to be include()d this stored
    // doc_comment becomes owned by the first thing the compiler sees in the file that it considers might have a
    // docblock. If the first thing in the file is a class without a doc block this would cause calls to
    // getDocBlock() on said class to return our long lost doc_comment. Argh.
    // To workaround, cause the parser to parse an empty docblock. Sure getDocBlock() will return this, but at least
    // it's harmless to us.
    token_get_all("<?php\n/**\n *\n */");
    $this->numTokens = count($this->tokens);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal