略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: PhpToken

2024-04-28

The PhpToken class

(PHP 8)

简介

This class provides an alternative to token_get_all(). While the function returns tokens either as a single-character string, or an array with a token ID, token text and line number, PhpToken::tokenize() normalizes all tokens into PhpToken objects, which makes code operating on tokens more memory efficient and readable.

类摘要

class PhpToken implements Stringable {
/* 属性 */
public int $id;
public string $text;
public int $line;
public int $pos;
/* 方法 */
final public __construct(
    int $id,
    string $text,
    int $line = -1,
    int $pos = -1
)
public getTokenName(): ?string
public is(int|string|array $kind): bool
public isIgnorable(): bool
public __toString(): string
public static tokenize(string $code, int $flags = 0): array
}

属性

id

One of the T_* constants, or an ASCII codepoint representing a single-char token.

text

The textual content of the token.

line

The starting line number (1-based) of the token.

pos

The starting position (0-based) in the tokenized string.

目录

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/class.phptoken.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3