PhpParser\Lexer::startLexing PHP Method

startLexing() public method

This function does not throw if lexing errors occur. Instead, errors may be retrieved using the getErrors() method.
public startLexing ( string $code, phpparser\ErrorHandler $errorHandler = null )
$code string The source code to lex
$errorHandler phpparser\ErrorHandler Error handler to use for lexing errors. Defaults to ErrorHandler\Throwing
    public function startLexing($code, ErrorHandler $errorHandler = null)
    {
        if (null === $errorHandler) {
            $errorHandler = new ErrorHandler\Throwing();
        }
        $this->code = $code;
        // keep the code around for __halt_compiler() handling
        $this->pos = -1;
        $this->line = 1;
        $this->filePos = 0;
        // If inline HTML occurs without preceding code, treat it as if it had a leading newline.
        // This ensures proper composability, because having a newline is the "safe" assumption.
        $this->prevCloseTagHasNewline = true;
        $scream = ini_set('xdebug.scream', '0');
        $this->resetErrors();
        $this->tokens = @token_get_all($code);
        $this->handleErrors($errorHandler);
        if (false !== $scream) {
            ini_set('xdebug.scream', $scream);
        }
    }

Usage Example

Example #1
0
 public function startLexing($code, ErrorHandler $errorHandler = null)
 {
     $this->inObjectAccess = false;
     parent::startLexing($code, $errorHandler);
     if ($this->requiresEmulation($code)) {
         $this->emulateTokens();
     }
 }
All Usage Examples Of PhpParser\Lexer::startLexing