大网数据广告活动
PHP 语言与运行手册

The PhpToken class

· 52CE 我爱测

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 t

The PhpToken class

(PHP 8)

Introduction

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 synopsis

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

Properties

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 (the number of bytes).

Table of Contents

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。